Files
babylonjs-sdk-ts/scripts/postbuild.cjs
2026-01-05 09:41:23 +08:00

21 lines
607 B
JavaScript

const fs = require('fs');
const path = require('path');
const projectRoot = path.resolve(__dirname, '..');
const srcIndex = path.join(projectRoot, 'index.html');
const distDir = path.join(projectRoot, 'dist');
const distIndex = path.join(distDir, 'index.html');
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true });
}
let html = fs.readFileSync(srcIndex, 'utf8');
// 替换开发路径为构建产物路径
html = html.replace(/['"]\/src\/main\.ts['"]/g, '"/assets/index.js"');
fs.writeFileSync(distIndex, html, 'utf8');
console.log('postbuild: index.html written to dist/');