Commit a85a639f authored by 胡's avatar

feat: dist 目录统一删除esmodule内容脚本

parent 34e168c4
function main() {
const fs = require('node:fs')
let dirInfo = fs.readdirSync('./dist')
if(!dirInfo.length) return console.log('无dist文件夹')
for (let index = 0; index < dirInfo.length; index++) {
let indexHtmlPath = './dist/' + dirInfo[index] + '/index.html'
fs.readFile(indexHtmlPath, 'utf8', (err, dataStr) => {
if (err) return console.log("读取文件失败!" + err.message);
let str = dataStr.toString()
const delContent = str.match(/<script.*?data-src="[^"]*".*?>([\s\S]*?)<\/script>/)[1]
str = str.replace(/<script type="module"(([\s\S])*?)<\/script>/g, '')
str = str.replace(/nomodule/g, '')
.replace(/crossorigin/g, '')
.replace(delContent, '')
.replace(/data-src/g, 'src')
fs.writeFile(indexHtmlPath, str, function (err) {
if (err) return err;
console.log(indexHtmlPath + '页面替换成功')
});
})
}
}
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment