const fs = require('fs'); const path = require('path'); const indexPath = path.resolve(__dirname, 'dist/index.html'); let indexHtml = fs.readFileSync(indexPath, 'utf-8'); const timestamp = new Date().getTime(); // 正则表达式匹配JS文件引用并添加时间戳 indexHtml = indexHtml.replace(/`; } return match; }); fs.writeFileSync(indexPath, indexHtml);