huangxingxing 1 tahun lalu
induk
melakukan
3d9f366755
4 mengubah file dengan 13 tambahan dan 24 penghapusan
  1. 3 12
      .env.development
  2. 3 5
      .env.production
  3. 2 2
      package.json
  4. 5 5
      vite.config.ts

+ 3 - 12
.env.development

@@ -1,12 +1,3 @@
-# 开发环境
-# 使用VUE_CLI_BABEL_TRANSPILE_MODULES环境变量,控制是否启用babel-plugin-dynamic-import-node插件,将所有import()转换为require()。
-# 当有大量的页面时,这种配置可以显著提高热更新的速度。
-
-ENV = 'development'
-
-VUE_APP_BASE_API = '/api'
-VUE_APP_BASE_websokt = '/192.168.0.131'
-//VUE_APP_BASE_websokt = '/192.168.0.43'
-//VUE_APP_BASE_websokt = '/www.adicn.com'
-
-VUE_CLI_BABEL_TRANSPILE_MODULES = true
+NODE_ENV = 'development'
+VITE_NAME='开发环境'
+VITE_BASE_URL = 'http://192.168.0.131:8187/TransServlet'

+ 3 - 5
.env.production

@@ -1,7 +1,5 @@
 # 正式环境
 
-ENV = 'production'
-
-VUE_APP_BASE_API = '/disaster'
-
-VUE_APP_BASE_websokt = '/www.adicn.com'
+NODE_ENV = 'production'
+VITE_NAME='生产环境'
+VITE_BASE_URL = '/disaster/TransServlet'

+ 2 - 2
package.json

@@ -4,8 +4,8 @@
   "version": "0.0.0",
   "type": "module",
   "scripts": {
-    "dev": "vite",
-    "build": "vite build",
+    "dev": "vite --mode development",
+    "build": "vite build --mode production",
     "preview": "vite preview",
     "lint:script": "eslint --ext .jsx,.vue,.tsx,.ts,.js --fix"
   },

+ 5 - 5
vite.config.ts

@@ -13,7 +13,9 @@ import Components from 'unplugin-vue-components/vite'
 import VueSetupExtend from 'vite-plugin-vue-setup-extend'
 
 // https://vitejs.dev/config/
-export default defineConfig({
+export default defineConfig(({command,mode})=>{
+    const config = loadEnv (mode,'./');
+    return{
     base:"./",
     plugins: [
         vue(),
@@ -42,10 +44,7 @@ export default defineConfig({
     server: {
         proxy: {
             '/api': {
-                // target: 'http://localhost:8081/', // 后端接口地址
-                target: 'http://192.168.0.131:8187/TransServlet',
-                //target: 'http://192.168.0.131:8087/TransServlet',
-                // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
+                target: config.VITE_BASE_URL,//配置文件获取地址
                 secure: false, //接受使用https
                 changeOrigin: true, //允许跨域
                 ws: false, //使用websocket
@@ -70,4 +69,5 @@ export default defineConfig({
               
         }
     }
+}
 })