// vite.config.ts
// 打包时间
function buildTimePlugin(mode) {
console.log('mode :>> ', mode)
return {
name: 'build-time',
// 在 buildStart 阶段设置初始值
buildStart() {
this.startTime = Date.now()
if (mode !== 'development') console.log('开始打包')
},
// 输出打包时间
closeBundle(options, bundle) {
const timeDiff = (Date.now() - this.startTime) / 1000
if (mode !== 'development') console.log(`打包结束 ${timeDiff}s`)
}
}
}
export default ({ mode }: ConfigEnv): UserConfig => {
...
plugins:[
...
//注意,打包插件放最后更准确
buildTimePlugin(mode)
]
}
标签:插件,console,log,自定义,vite,打包,mode
From: https://www.cnblogs.com/hjk1124/p/18189775