Przeglądaj źródła

启动环境修改

cm 9 miesięcy temu
rodzic
commit
1f8e0badc6
6 zmienionych plików z 15 dodań i 5 usunięć
  1. 0 2
      .env
  2. 3 0
      .env.development
  3. 3 0
      .env.production
  4. 2 2
      src/api/request.ts
  5. 3 0
      src/main.ts
  6. 4 1
      vite.config.ts

+ 0 - 2
.env

@@ -1,5 +1,3 @@
 
 # port
 VITE_PORT = 8100
-
-

+ 3 - 0
.env.development

@@ -3,3 +3,6 @@ NODE_ENV = 'development'
 
 # 本地环境接口地址
 VUE_APP_BASE_API = '/api'
+
+# 本地环境接口地址
+VITE_APP_BASE_URL = 'http://127.0.0.1:8001/api'

+ 3 - 0
.env.production

@@ -3,3 +3,6 @@ NODE_ENV = "production"
 
 # 线上环境接口地址
 VUE_APP_BASE_API = '/api'
+
+# 本地环境接口地址
+VITE_APP_BASE_URL = 'http://119.3.32.162:8001/api'

+ 2 - 2
src/api/request.ts

@@ -4,9 +4,9 @@ import { useUserStore } from "@/store/modules/user"
 // 创建axios实例 进行基本参数配置
 const service = axios.create({
     // 默认请求地址,根据环境的不同可在.env 文件中进行修改
-    // baseURL: import.meta.env.VUE_APP_BASE_
+    baseURL: import.meta.env.VITE_APP_BASE_URL,
     // 本地地址
-    baseURL: "http://127.0.0.1:8001/api",
+    // baseURL: "http://127.0.0.1:8001/api",
     // baseURL: "http://119.91.156.147:1007/api",
     // 华为云地址
     // baseURL: "http://119.3.32.162:666/api",

+ 3 - 0
src/main.ts

@@ -31,3 +31,6 @@ app.component('PageWrapLayout',PageWrapLayout)
 app.use(pinia)
 app.use(router)
 app.use(ElementPlus).mount('#app')
+
+console.log('Base URL:', import.meta.env.VITE_APP_BASE_URL);
+

+ 4 - 1
vite.config.ts

@@ -83,7 +83,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
     // },
 
     build: {
-      minify:"terser",
+      minify: "terser",
       outDir: 'dist',
       assetsDir: 'assets',
       sourcemap: false,
@@ -94,6 +94,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
         },
       },
     },
+    define: {
+      'process.env': process.env
+    }
   }
 
 })