| | |
| | | const env = loadEnv(mode, process.cwd()); |
| | | const { VITE_APP_ENV } = env; |
| | | const baseUrl = |
| | | env.VITE_APP_ENV === "development" |
| | | ? "http://1.15.17.182:9003" |
| | | : env.VITE_BASE_API; |
| | | env.VITE_APP_ENV === "development" |
| | | ? "http://192.168.1.35:9009" |
| | | : env.VITE_BASE_API; |
| | | const javaUrl = |
| | | env.VITE_APP_ENV === "development" |
| | | ? "http://1.15.17.182:9002" |
| | | : env.VITE_JAVA_API; |
| | | env.VITE_APP_ENV === "development" |
| | | ? "http://192.168.1.35:9009" |
| | | : env.VITE_JAVA_API; |
| | | |
| | | return { |
| | | define:{ |
| | | __BASE_API__: JSON.stringify(javaUrl) |
| | | define: { |
| | | __BASE_API__: JSON.stringify(javaUrl), |
| | | }, |
| | | base: VITE_APP_ENV === "production" ? "/" : "/", |
| | | plugins: createVitePlugins(env, command === "build"), |
| | |
| | | "@": path.resolve(__dirname, "./src"), |
| | | }, |
| | | extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"], |
| | | dedupe: ['vue', 'axios'], // 去重重复依赖 |
| | | dedupe: ["vue", "axios"], // 去重重复依赖 |
| | | }, |
| | | // 全局开启构建缓存(核心) |
| | | cacheDir: './node_modules/.vite', |
| | | cacheDir: |
| | | "/var/jenkins_home/workspace/客户-鹏创电子前端/node_modules/.vite", |
| | | // 依赖预构建优化 |
| | | optimizeDeps: { |
| | | include: ['vue', 'axios', 'element-plus', 'echarts'], // 根据项目依赖调整 |
| | | disabled: false, |
| | | include: ["vue", "axios", "element-plus", "echarts"], // 根据项目依赖调整 |
| | | esbuildOptions: { |
| | | target: 'es2020', |
| | | worker: true, // 开启 esbuild 多线程 |
| | | } |
| | | target: "es2020", |
| | | }, |
| | | }, |
| | | // 打包配置(核心优化区) |
| | | build: { |
| | |
| | | outDir: "dist", |
| | | assetsDir: "assets", |
| | | chunkSizeWarningLimit: 2000, |
| | | minify: 'esbuild', // 使用 esbuild 压缩(无需额外依赖) |
| | | minify: "esbuild", // 使用 esbuild 压缩(无需额外依赖) |
| | | reportCompressedSize: false, // 关闭产物体积报告,减少耗时 |
| | | commonjsOptions: { |
| | | include: [/node_modules/, /\.commonjs$/], |
| | |
| | | assetFileNames: "static/[ext]/[name]-[hash].[ext]", |
| | | // 分包策略(拆分大依赖) |
| | | manualChunks: { |
| | | vendor: ['vue', 'vue-router', 'pinia', 'axios'], |
| | | ui: ['element-plus'], // 根据实际UI库调整 |
| | | charts: ['echarts'], // 有图表库则保留,无则删除 |
| | | vendor: ["vue", "vue-router", "pinia", "axios"], |
| | | ui: ["element-plus"], // 根据实际UI库调整 |
| | | charts: ["echarts"], // 有图表库则保留,无则删除 |
| | | }, |
| | | }, |
| | | cache: true, |
| | | }, |
| | | }, |
| | | server: { |
| | | port: 80, |
| | | port: 8001, |
| | | host: true, |
| | | open: true, |
| | | proxy: { |
| | |
| | | // CSS 预编译缓存 |
| | | preprocessorOptions: { |
| | | scss: { |
| | | cacheDirectory: path.resolve(__dirname, './node_modules/.vite/scss-cache'), |
| | | cacheDirectory: path.resolve( |
| | | __dirname, |
| | | "./node_modules/.vite/scss-cache" |
| | | ), |
| | | }, |
| | | }, |
| | | }, |
| | | // esbuild 全局配置 |
| | | esbuild: { |
| | | logOverride: { 'this-is-undefined-in-esm': 'silent' }, |
| | | target: 'es2020', |
| | | logOverride: { "this-is-undefined-in-esm": "silent" }, |
| | | target: "es2020", |
| | | }, |
| | | }; |
| | | }); |
| | | }); |