yuanmingze vor 4 Tagen
Ursprung
Commit
c8341d9041
1 geänderte Dateien mit 35 neuen und 2 gelöschten Zeilen
  1. 35 2
      vite.config.ts

+ 35 - 2
vite.config.ts

@@ -1,5 +1,5 @@
 // vite.config.ts
-import { defineConfig } from 'vite'
+import { defineConfig, loadEnv } from 'vite'
 import UniKuRoot from '@uni-ku/root'
 import uni from '@dcloudio/vite-plugin-uni'
 import AutoImport from 'unplugin-auto-import/vite'
@@ -7,8 +7,10 @@ import Components from '@uni-helper/vite-plugin-uni-components'
 import { WotResolver } from './resolvers/wot-ui-resolver'
 import path from 'path'
 
-export default defineConfig(async () => {
+export default defineConfig(async ({ mode }) => {
   const { default: tsconfigPaths } = await import('vite-tsconfig-paths')
+  const { VITE_BASE_API } = loadEnv(mode, process.cwd())
+  const isH5 = process.env.UNI_PLATFORM === 'h5'
 
   return {
     plugins: [
@@ -29,5 +31,36 @@ export default defineConfig(async () => {
         '@': path.resolve(__dirname, 'src'),
       },
     },
+
+    ...(isH5
+      ? {
+          build: {
+            rollupOptions: {
+              output: {
+                entryFileNames: 'assets/[name]-[hash].js',
+                chunkFileNames: 'assets/[name]-[hash].js',
+                assetFileNames: 'assets/[name]-[hash][extname]',
+              },
+            },
+          },
+        }
+      : {}),
+
+    server: {
+      proxy: {
+        '/admin': {
+          target: VITE_BASE_API,
+          changeOrigin: true,
+        },
+        '/auth': {
+          target: VITE_BASE_API,
+          changeOrigin: true,
+        },
+        '/gig': {
+          target: VITE_BASE_API,
+          changeOrigin: true,
+        },
+      },
+    },
   }
 })