| | |
| | | const env = loadEnv(mode, process.cwd()); |
| | | const { VITE_APP_ENV } = env; |
| | | const baseUrl = |
| | | VITE_APP_ENV == "development" |
| | | ? "http://114.132.189.42:9036" // 开发环境后端接口 |
| | | : "http://114.132.189.42:9036"; // 生产环境后端接口 |
| | | env.VITE_APP_ENV === "development" |
| | | ? "http://192.168.1.35:9009" |
| | | : env.VITE_BASE_API; |
| | | const javaUrl = |
| | | env.VITE_APP_ENV === "development" |
| | | ? "http://192.168.1.35:9009" |
| | | : env.VITE_JAVA_API; |
| | | |
| | | return { |
| | | // 部署生产环境和开发环境下的URL。 |
| | | // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上 |
| | | // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 |
| | | define: { |
| | | __BASE_API__: JSON.stringify(javaUrl), |
| | | }, |
| | | base: VITE_APP_ENV === "production" ? "/" : "/", |
| | | plugins: createVitePlugins(env, command === "build"), |
| | | resolve: { |
| | | // https://cn.vitejs.dev/config/#resolve-alias |
| | | alias: { |
| | | // 设置路径 |
| | | "~": path.resolve(__dirname, "./"), |
| | | // 设置别名 |
| | | "@": path.resolve(__dirname, "./src"), |
| | | }, |
| | | // https://cn.vitejs.dev/config/#resolve-extensions |
| | | extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"], |
| | | dedupe: ["vue", "axios"], // 去重重复依赖 |
| | | }, |
| | | // 打包配置 |
| | | // 全局开启构建缓存(核心) |
| | | cacheDir: |
| | | "/var/jenkins_home/workspace/客户-鹏创电子前端/node_modules/.vite", |
| | | // 依赖预构建优化 |
| | | optimizeDeps: { |
| | | include: ["vue", "axios", "element-plus", "echarts"], // 根据项目依赖调整 |
| | | esbuildOptions: { |
| | | target: "es2020", |
| | | }, |
| | | }, |
| | | // 打包配置(核心优化区) |
| | | build: { |
| | | // https://vite.dev/config/build-options.html |
| | | sourcemap: command === "build" ? false : "inline", |
| | | sourcemap: false, // 彻底关闭生产环境sourcemap |
| | | outDir: "dist", |
| | | assetsDir: "assets", |
| | | chunkSizeWarningLimit: 2000, |
| | | minify: "esbuild", // 使用 esbuild 压缩(无需额外依赖) |
| | | reportCompressedSize: false, // 关闭产物体积报告,减少耗时 |
| | | commonjsOptions: { |
| | | include: [/node_modules/, /\.commonjs$/], |
| | | }, |
| | | rollupOptions: { |
| | | output: { |
| | | chunkFileNames: "static/js/[name]-[hash].js", |
| | | entryFileNames: "static/js/[name]-[hash].js", |
| | | assetFileNames: "static/[ext]/[name]-[hash].[ext]", |
| | | // 分包策略(拆分大依赖) |
| | | manualChunks: { |
| | | vendor: ["vue", "vue-router", "pinia", "axios"], |
| | | ui: ["element-plus"], // 根据实际UI库调整 |
| | | charts: ["echarts"], // 有图表库则保留,无则删除 |
| | | }, |
| | | }, |
| | | cache: true, |
| | | }, |
| | | }, |
| | | // vite 相关配置 |
| | | server: { |
| | | port: 80, |
| | | port: 8001, |
| | | host: true, |
| | | open: true, |
| | | proxy: { |
| | | // https://cn.vitejs.dev/config/#server-proxy |
| | | "/dev-api": { |
| | | target: baseUrl, |
| | | changeOrigin: true, |
| | | rewrite: (p) => p.replace(/^\/dev-api/, ""), |
| | | }, |
| | | // springdoc proxy |
| | | "^/v3/api-docs/(.*)": { |
| | | target: baseUrl, |
| | | changeOrigin: true, |
| | |
| | | }, |
| | | ], |
| | | }, |
| | | // CSS 预编译缓存 |
| | | preprocessorOptions: { |
| | | scss: { |
| | | cacheDirectory: path.resolve( |
| | | __dirname, |
| | | "./node_modules/.vite/scss-cache" |
| | | ), |
| | | }, |
| | | }, |
| | | }, |
| | | // esbuild 全局配置 |
| | | esbuild: { |
| | | logOverride: { "this-is-undefined-in-esm": "silent" }, |
| | | target: "es2020", |
| | | }, |
| | | }; |
| | | }); |