123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import { defineConfig, loadEnv } from "vite"
- import { resolve } from "path"
- import createVitePlugins from "./vite/plugins"
- //import { visualizer } from "rollup-plugin-visualizer"
- // https://vitejs.dev/config/
- export default defineConfig(({ mode, command }) => {
- const env = loadEnv(mode, process.cwd())
- return {
- // 部署生产环境和开发环境下的URL。
- // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
- // 例如 https://www.vber.net/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.vber.net/admin/,则设置 baseUrl 为 /admin/。
- base: env.VITE_APP_CONTEXT_PATH,
- plugins: [
- ...createVitePlugins(env, command === "build")
- //,visualizer()
- ],
- build: {
- minify: "terser", // 启用 terser 压缩
- terserOptions: {
- compress: {
- pure_funcs: ["console.log"], // 只删除 console.log
- //drop_console: true, // 删除所有 console
- drop_debugger: true // 删除 debugger
- }
- },
- rollupOptions: {
- output: {
- // 最小化拆分包
- manualChunks(id) {
- if (id.includes("node_modules")) {
- if (id.includes("node_modules/element-plus")) {
- return "vb_plugin_element-plus"
- }
- if (id.includes("node_modules/nprogress")) {
- return "vb_plugin_nprogress" //单独打包
- }
- if (id.includes("node_modules/quill")) {
- return "vb_plugin_quill"
- }
- if (id.includes("node_modules/echarts")) {
- return "vb_plugin_echarts"
- }
- if (id.includes("node_modules/lodash")) {
- return "vb_plugin_lodash"
- }
- // 通过拆分包的方式将所有来自node_modules的模块打包到单独的chunk中
- return "vb_plugin_vendor"
- }
- // 将pinia的全局库单独打包,避免和页面一起打包造成资源重复引入
- if (id.includes(resolve(__dirname, "/src/stores/index.ts"))) {
- return "vb_store"
- }
- if (id.includes("/src/components/") && id.includes("/Vb")) {
- return "vb_components"
- }
- if (id.includes("/src/core/utils/") && id.includes("/Vb")) {
- return "vb_utils"
- }
- },
- // 设置chunk的文件名格式
- chunkFileNames: (chunkInfo) => {
- if (chunkInfo.isEntry) {
- return "index.[hash].js"
- }
- if (chunkInfo.name === "index") {
- const facadeModuleId = chunkInfo.facadeModuleId
- ? chunkInfo.facadeModuleId.split("/")
- : []
- const fileName = facadeModuleId[facadeModuleId.length - 2] || "[name]"
- // 根据chunk的facadeModuleId(入口模块的相对路径)生成chunk的文件名
- return `js/vb_view_${fileName}.[hash].js`
- }
- return `js/[name].[hash].js`
- },
- // 设置入口文件的文件名格式
- entryFileNames: "js/[name].[hash].js",
- // 设置静态资源文件的文件名格式
- assetFileNames(assetInfo) {
- if (assetInfo.name?.endsWith(".css")) {
- return "css/[name].[hash].[ext]"
- }
- const imgArray = [".png", "jpg", ".jpeg", "webp ", ".svg", ".gif"]
- if (imgArray.some((v) => assetInfo.name?.endsWith(v))) {
- return "img/[name].[hash].[ext]"
- }
- return "media/asset/[name].[hash:4].[ext]"
- }
- }
- }
- },
- resolve: {
- // https://cn.vitejs.dev/config/#resolve-alias
- alias: {
- "@a": resolve(__dirname, "./src/api"),
- "@s": resolve(__dirname, "./src/stores"),
- "@r": resolve(__dirname, "./src/router"),
- "@v": resolve(__dirname, "./src/views"),
- "@@": resolve(__dirname, "./src/core"),
- "@@@": resolve(__dirname, "./src/components"),
- "@com": resolve(__dirname, "./src/components"),
- "@": resolve(__dirname, "./src"),
- "~": resolve(__dirname, "./")
- },
- // https://cn.vitejs.dev/config/#resolve-extensions
- extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"]
- },
- // vite 相关配置
- server: {
- port: Number(env.VITE_APP_PORT),
- // host: true,
- host: "0.0.0.0",
- // 热更新
- hmr: true,
- // 设为 true 时若端口已被占用则会直接退出,而不是尝试下一个可用端口
- strictPort: true,
- open: true,
- proxy: {
- [env.VITE_APP_BASE_API]: {
- //target: "http://localhost:8080",
- target: env.VITE_APP_PROXY_URL,
- changeOrigin: true,
- rewrite: (path) => path.replace(new RegExp("^" + env.VITE_APP_BASE_API), "")
- }
- }
- },
- preview: {
- port: 6666,
- // host: true,
- host: "0.0.0.0",
- // 热更新
- hmr: true,
- // 设为 true 时若端口已被占用则会直接退出,而不是尝试下一个可用端口
- strictPort: true,
- open: true,
- cors: false,
- proxy: {
- // "/prod-api": {
- // target: "http://localhost:6060",
- // changeOrigin: true,
- // rewrite: (p) => p.replace(/^\/prod-api/, ""),
- // }, 1
- "/prod-api": {
- target: "http://192.168.0.82:6066",
- changeOrigin: true,
- rewrite: (p) => p.replace(/^\/prod-api/, "/prod-api")
- }
- }
- },
- // 预编译
- optimizeDeps: {
- include: [
- "vue",
- "vue-router",
- "pinia",
- "axios",
- "@vueuse/core",
- "path-to-regexp",
- "echarts",
- "vue-i18n",
- "@vueup/vue-quill",
- "bpmn-js/lib/Viewer",
- "bpmn-js/lib/Modeler.js",
- "bpmn-js-properties-panel",
- "min-dash",
- "diagram-js/lib/navigation/movecanvas",
- "diagram-js/lib/navigation/zoomscroll",
- "bpmn-js/lib/features/palette/PaletteProvider",
- "bpmn-js/lib/features/context-pad/ContextPadProvider",
- "diagram-js/lib/draw/BaseRenderer",
- "tiny-svg",
- "image-conversion",
- "element-plus/es/components/**/css"
- ]
- }
- }
- })
|