1.新增buildTimePlugin(mode)插件
export default ({ mode }) => { process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }; let dist = "dist-collect"; const env = process.env.VITE_NODE_ENV; if(env){ if (env.startsWith("form")) { dist = "dist-collect"; } else if (env.startsWith("process")) { dist = "dist-smart-process"; } } return defineConfig({ plugins: [vue(), buildTimePlugin(mode)], build: { outDir: dist, }, resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, }, base: process.env.VITE_APP_BASE_URI, }); };
2.设置输出打包时间
function buildTimePlugin(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`); }, } }
标签:buildTimePlugin,dist,process,新增,Vite,env,打包,mode From: https://www.cnblogs.com/luoyihao/p/17646003.html