vite 自定義插件獲取打包時長

// 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) ] }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章