wangxx 4 ヶ月 前
コミット
46f33ec0ca
共有1 個のファイルを変更した79 個の追加0 個の削除を含む
  1. 79 0
      vite.config.js

+ 79 - 0
vite.config.js

@@ -0,0 +1,79 @@
1
+import { defineConfig, loadEnv } from 'vite'
2
+import path from 'path'
3
+import createVitePlugins from './vite/plugins'
4
+
5
+const baseUrl = 'http://192.168.3.221:8088' // 后端接口
6
+
7
+// https://vitejs.dev/config/
8
+export default defineConfig(({ mode, command }) => {
9
+  const env = loadEnv(mode, process.cwd())
10
+  const { VITE_APP_ENV } = env
11
+  return {
12
+    // 部署生产环境和开发环境下的URL。
13
+    // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
14
+    // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
15
+    base: VITE_APP_ENV === 'production' ? '/' : '/',
16
+    plugins: createVitePlugins(env, command === 'build'),
17
+    resolve: {
18
+      // https://cn.vitejs.dev/config/#resolve-alias
19
+      alias: {
20
+        // 设置路径
21
+        '~': path.resolve(__dirname, './'),
22
+        // 设置别名
23
+        '@': path.resolve(__dirname, './src')
24
+      },
25
+      // https://cn.vitejs.dev/config/#resolve-extensions
26
+      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
27
+    },
28
+    // 打包配置
29
+    build: {
30
+      // https://vite.dev/config/build-options.html
31
+      sourcemap: command === 'build' ? false : 'inline',
32
+      outDir: 'dist',
33
+      assetsDir: 'assets',
34
+      chunkSizeWarningLimit: 2000,
35
+      rollupOptions: {
36
+        output: {
37
+          chunkFileNames: 'static/js/[name]-[hash].js',
38
+          entryFileNames: 'static/js/[name]-[hash].js',
39
+          assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
40
+        }
41
+      }
42
+    },
43
+    // vite 相关配置
44
+    server: {
45
+      port: 8111,
46
+      host: true,
47
+      open: true,
48
+      proxy: {
49
+        // https://cn.vitejs.dev/config/#server-proxy
50
+        '/dev-api': {
51
+          target: baseUrl,
52
+          changeOrigin: true,
53
+          rewrite: (p) => p.replace(/^\/dev-api/, '')
54
+        },
55
+        // springdoc proxy
56
+        '^/v3/api-docs/(.*)': {
57
+          target: baseUrl,
58
+          changeOrigin: true,
59
+        }
60
+      }
61
+    },
62
+    css: {
63
+      postcss: {
64
+        plugins: [
65
+          {
66
+            postcssPlugin: 'internal:charset-removal',
67
+            AtRule: {
68
+              charset: (atRule) => {
69
+                if (atRule.name === 'charset') {
70
+                  atRule.remove()
71
+                }
72
+              }
73
+            }
74
+          }
75
+        ]
76
+      }
77
+    }
78
+  }
79
+})