打包后新增元素展示打包时间
plugins: [
{
name: 'html-transform',
apply: 'build',
enforce: 'post',
closeBundle() {
const buildTime = new Date().toISOString();
const indexPath = path.resolve(__dirname, 'dist', 'index.html');
let html = fs.readFileSync(indexPath, { encoding: 'utf-8' });
html = html.replace('</body>', `<div style="display:none" id="buildTime">${moment(buildTime).format('YYYY-MM-DD HH:mm:ss')}</div></body>`);
fs.writeFileSync(indexPath, html);
}
}
],
开发环境此处配置无效,打包完成后呈现以下效果
方便确认部署后的包是否拉取的是最新代码