1
jhzh
2025-08-24 e5ee6d81bc05fbf35ff65a2bb6eed1553d65fa18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * vue 一键修复dist包path
 * vite.config.js 先配置 @vitejs/plugin-legacy 和 base:'./'
 * 参考:https://www.jianshu.com/p/d44d14bc5344
 * 配置完成后 路径正常后 再 node fixDistPath.js
 */
 
import fs from 'fs';
const distPath = './dist/index.html';//打包路径的index.html
let htmlText = fs.readFileSync(distPath, 'utf8');
let resultText = '';
let htmlArr = htmlText.match(/.*\n/g) || [];
htmlArr.forEach(str => {
    str = str.replace(/\s?nomodule\s?/g,' ');
    str = str.replace(/\s?crossorigin\s?/g,' ');
    str = str.replace(/data-src/g,'src');
    if(!/type="module"/i.test(str)) resultText += str;
});
fs.writeFileSync(distPath,resultText,'utf8');
console.log('success');