init
This commit is contained in:
20
scripts/postbuild.cjs
Normal file
20
scripts/postbuild.cjs
Normal file
@ -0,0 +1,20 @@
|
||||
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/');
|
||||
Reference in New Issue
Block a user