Sfoglia il codice sorgente

feat(vite): add env config for proxy target

0xJacky 1 anno fa
parent
commit
d2ba3ebad3
5 ha cambiato i file con 72 aggiunte e 67 eliminazioni
  1. 1 1
      app/package.json
  2. 14 14
      app/pnpm-lock.yaml
  3. 1 1
      app/src/version.json
  4. 1 1
      app/version.json
  5. 55 50
      app/vite.config.ts

+ 1 - 1
app/package.json

@@ -67,7 +67,7 @@
     "unplugin-auto-import": "^0.17.1",
     "unplugin-vue-components": "^0.25.2",
     "unplugin-vue-define-options": "^1.4.0",
-    "vite": "^5.0.5",
+    "vite": "^5.0.7",
     "vite-plugin-html": "^3.2.0",
     "vite-svg-loader": "^5.1.0",
     "vue-tsc": "^1.8.22"

+ 14 - 14
app/pnpm-lock.yaml

@@ -111,10 +111,10 @@ devDependencies:
     version: 6.13.1(eslint@8.55.0)(typescript@5.3.2)
   '@vitejs/plugin-vue':
     specifier: ^4.5.0
-    version: 4.5.1(vite@5.0.5)(vue@3.3.10)
+    version: 4.5.1(vite@5.0.7)(vue@3.3.10)
   '@vitejs/plugin-vue-jsx':
     specifier: ^3.1.0
-    version: 3.1.0(vite@5.0.5)(vue@3.3.10)
+    version: 3.1.0(vite@5.0.7)(vue@3.3.10)
   '@vue/compiler-sfc':
     specifier: ^3.3.10
     version: 3.3.10
@@ -170,11 +170,11 @@ devDependencies:
     specifier: ^1.4.0
     version: 1.4.0(vue@3.3.10)
   vite:
-    specifier: ^5.0.5
-    version: 5.0.5(@types/node@20.10.2)(less@4.2.0)
+    specifier: ^5.0.7
+    version: 5.0.7(@types/node@20.10.2)(less@4.2.0)
   vite-plugin-html:
     specifier: ^3.2.0
-    version: 3.2.0(vite@5.0.5)
+    version: 3.2.0(vite@5.0.7)
   vite-svg-loader:
     specifier: ^5.1.0
     version: 5.1.0(vue@3.3.10)
@@ -1332,7 +1332,7 @@ packages:
     resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==}
     dev: true
 
-  /@vitejs/plugin-vue-jsx@3.1.0(vite@5.0.5)(vue@3.3.10):
+  /@vitejs/plugin-vue-jsx@3.1.0(vite@5.0.7)(vue@3.3.10):
     resolution: {integrity: sha512-w9M6F3LSEU5kszVb9An2/MmXNxocAnUb3WhRr8bHlimhDrXNt6n6D2nJQR3UXpGlZHh/EsgouOHCsM8V3Ln+WA==}
     engines: {node: ^14.18.0 || >=16.0.0}
     peerDependencies:
@@ -1342,20 +1342,20 @@ packages:
       '@babel/core': 7.23.5
       '@babel/plugin-transform-typescript': 7.23.5(@babel/core@7.23.5)
       '@vue/babel-plugin-jsx': 1.1.5(@babel/core@7.23.5)
-      vite: 5.0.5(@types/node@20.10.2)(less@4.2.0)
+      vite: 5.0.7(@types/node@20.10.2)(less@4.2.0)
       vue: 3.3.10(typescript@5.3.2)
     transitivePeerDependencies:
       - supports-color
     dev: true
 
-  /@vitejs/plugin-vue@4.5.1(vite@5.0.5)(vue@3.3.10):
+  /@vitejs/plugin-vue@4.5.1(vite@5.0.7)(vue@3.3.10):
     resolution: {integrity: sha512-DaUzYFr+2UGDG7VSSdShKa9sIWYBa1LL8KC0MNOf2H5LjcTPjob0x8LbkqXWmAtbANJCkpiQTj66UVcQkN2s3g==}
     engines: {node: ^14.18.0 || >=16.0.0}
     peerDependencies:
       vite: ^4.0.0 || ^5.0.0
       vue: ^3.2.25
     dependencies:
-      vite: 5.0.5(@types/node@20.10.2)(less@4.2.0)
+      vite: 5.0.7(@types/node@20.10.2)(less@4.2.0)
       vue: 3.3.10(typescript@5.3.2)
     dev: true
 
@@ -5212,7 +5212,7 @@ packages:
       '@types/node': 20.10.2
       rimraf: 5.0.5
       typescript: 5.3.2
-      vite: 5.0.5(@types/node@20.10.2)(less@4.2.0)
+      vite: 5.0.7(@types/node@20.10.2)(less@4.2.0)
     transitivePeerDependencies:
       - less
       - lightningcss
@@ -5222,7 +5222,7 @@ packages:
       - terser
     dev: false
 
-  /vite-plugin-html@3.2.0(vite@5.0.5):
+  /vite-plugin-html@3.2.0(vite@5.0.7):
     resolution: {integrity: sha512-2VLCeDiHmV/BqqNn5h2V+4280KRgQzCFN47cst3WiNK848klESPQnzuC3okH5XHtgwHH/6s1Ho/YV6yIO0pgoQ==}
     peerDependencies:
       vite: '>=2.0.0'
@@ -5239,7 +5239,7 @@ packages:
       html-minifier-terser: 6.1.0
       node-html-parser: 5.4.2
       pathe: 0.2.0
-      vite: 5.0.5(@types/node@20.10.2)(less@4.2.0)
+      vite: 5.0.7(@types/node@20.10.2)(less@4.2.0)
     dev: true
 
   /vite-svg-loader@5.1.0(vue@3.3.10):
@@ -5251,8 +5251,8 @@ packages:
       vue: 3.3.10(typescript@5.3.2)
     dev: true
 
-  /vite@5.0.5(@types/node@20.10.2)(less@4.2.0):
-    resolution: {integrity: sha512-OekeWqR9Ls56f3zd4CaxzbbS11gqYkEiBtnWFFgYR2WV8oPJRRKq0mpskYy/XaoCL3L7VINDhqqOMNDiYdGvGg==}
+  /vite@5.0.7(@types/node@20.10.2)(less@4.2.0):
+    resolution: {integrity: sha512-B4T4rJCDPihrQo2B+h1MbeGL/k/GMAHzhQ8S0LjQ142s6/+l3hHTT095ORvsshj4QCkoWu3Xtmob5mazvakaOw==}
     engines: {node: ^18.0.0 || >=20.0.0}
     hasBin: true
     peerDependencies:

+ 1 - 1
app/src/version.json

@@ -1 +1 @@
-{"version":"2.0.0-beta.6","build_id":76,"total_build":280}
+{"version":"2.0.0-beta.6","build_id":77,"total_build":281}

+ 1 - 1
app/version.json

@@ -1 +1 @@
-{"version":"2.0.0-beta.6","build_id":76,"total_build":280}
+{"version":"2.0.0-beta.6","build_id":77,"total_build":281}

+ 55 - 50
app/vite.config.ts

@@ -1,5 +1,5 @@
 import { URL, fileURLToPath } from 'node:url'
-import { defineConfig } from 'vite'
+import { defineConfig, loadEnv } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import Components from 'unplugin-vue-components/vite'
 import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
@@ -11,60 +11,65 @@ import AutoImport from 'unplugin-auto-import/vite'
 import DefineOptions from 'unplugin-vue-define-options/vite'
 
 // https://vitejs.dev/config/
-export default defineConfig({
-  base: './',
-  resolve: {
-    alias: {
-      '@': fileURLToPath(new URL('./src', import.meta.url)),
+export default defineConfig(({ mode }) => {
+  // eslint-disable-next-line n/prefer-global/process
+  const env = loadEnv(mode, process.cwd(), '')
+
+  return {
+    base: './',
+    resolve: {
+      alias: {
+        '@': fileURLToPath(new URL('./src', import.meta.url)),
+      },
+      extensions: [
+        '.mjs',
+        '.js',
+        '.ts',
+        '.jsx',
+        '.tsx',
+        '.json',
+        '.vue',
+        '.less',
+      ],
     },
-    extensions: [
-      '.mjs',
-      '.js',
-      '.ts',
-      '.jsx',
-      '.tsx',
-      '.json',
-      '.vue',
-      '.less',
-    ],
-  },
-  plugins: [
-    vue(),
-    vueJsx(),
+    plugins: [
+      vue(),
+      vueJsx(),
 
-    vitePluginBuildId(),
-    svgLoader(),
-    Components({
-      resolvers: [AntDesignVueResolver({ importStyle: false })],
-      directoryAsNamespace: true,
-    }),
-    AutoImport({
-      imports: ['vue', 'vue-router', 'pinia'],
-      vueTemplate: true,
-    }),
-    DefineOptions(),
-  ],
-  css: {
-    preprocessorOptions: {
-      less: {
-        modifyVars: {
-          'border-radius-base': '5px',
+      vitePluginBuildId(),
+      svgLoader(),
+      Components({
+        resolvers: [AntDesignVueResolver({ importStyle: false })],
+        directoryAsNamespace: true,
+      }),
+      AutoImport({
+        imports: ['vue', 'vue-router', 'pinia'],
+        vueTemplate: true,
+      }),
+      DefineOptions(),
+    ],
+    css: {
+      preprocessorOptions: {
+        less: {
+          modifyVars: {
+            'border-radius-base': '5px',
+          },
+          javascriptEnabled: true,
         },
-        javascriptEnabled: true,
       },
     },
-  },
-  server: {
-    proxy: {
-      '/api': {
-        target: 'http://127.0.0.1:9001/',
-        changeOrigin: true,
-        secure: false,
-        ws: true,
+    server: {
+      proxy: {
+        '/api': {
+          target: env.VITE_PROXY_TARGET || 'http://localhost:9000',
+          changeOrigin: true,
+          secure: false,
+          ws: true,
+        },
       },
     },
-  },
-  build: {
-    chunkSizeWarningLimit: 1000,
-  },
+    build: {
+      chunkSizeWarningLimit: 1000,
+    },
+  }
 })