Browse Source

Merge branch 'build_nh' into debug

jwyu 1 tháng trước cách đây
mục cha
commit
5cab2413c4
7 tập tin đã thay đổi với 57 bổ sung44 xóa
  1. 3 1
      .env.development
  2. 2 0
      .env.nh
  3. 3 1
      .env.production
  4. 3 1
      .env.test
  5. 1 0
      package.json
  6. 1 1
      src/router/index.ts
  7. 44 40
      vite.config.ts

+ 3 - 1
.env.development

@@ -1,2 +1,4 @@
 VITE_BASEURL = '/v1'
-VITE_HZYB_BASEURL = 'https://ybpctest.hzinsights.com/api'
+VITE_HZYB_BASEURL = 'https://ybpctest.hzinsights.com/api'
+# 路由根地址
+VITE_APP_BASE_URL="/"

+ 2 - 0
.env.nh

@@ -0,0 +1,2 @@
+# 路由根地址
+VITE_APP_BASE_URL="/eta-charts"

+ 3 - 1
.env.production

@@ -1,2 +1,4 @@
 VITE_BASEURL = '/v1'
-VITE_HZYB_BASEURL = 'https://yanbao.hzinsights.com/api'
+VITE_HZYB_BASEURL = 'https://yanbao.hzinsights.com/api'
+# 路由根地址
+VITE_APP_BASE_URL="/"

+ 3 - 1
.env.test

@@ -1,2 +1,4 @@
 VITE_BASEURL = '/v1'
-VITE_HZYB_BASEURL = 'https://ybpctest.hzinsights.com/api'
+VITE_HZYB_BASEURL = 'https://ybpctest.hzinsights.com/api'
+# 路由根地址
+VITE_APP_BASE_URL="/"

+ 1 - 0
package.json

@@ -5,6 +5,7 @@
     "dev": "vite",
     "build": " vite build --mode production",
     "build.test": "vite build --mode test",
+    "build.nh": "vite build --mode nh",
     "serve": "vite preview"
   },
   "dependencies": {

+ 1 - 1
src/router/index.ts

@@ -31,7 +31,7 @@ export const routes: AppRouteRecordRaw[] = [
 ];
 
 const router = createRouter({
-  history: createWebHistory(), //路由模式
+  history: createWebHistory(import.meta.env.VITE_APP_BASE_URL),
   routes,
 });
 

+ 44 - 40
vite.config.ts

@@ -1,53 +1,57 @@
-import { defineConfig } from 'vite'
+import { defineConfig,loadEnv } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import legacy from '@vitejs/plugin-legacy'
 import path from 'path'
 
 // https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [
-		vue(),
-		legacy({
-			polyfills: ['es.promise.finally', 'es/map', 'es/set'],
-      modernPolyfills: ['es.promise.finally']
-    })
-	],
-  server: {
-		port: 3000,
-    cors: true,
-		host: '0.0.0.0',
-		proxy: {
-			'/v1': {
-				// target: 'http://8.136.199.33:8608',
-				target: 'https://charttest.hzinsights.com',
-				changeOrigin: true,
-        rewrite: (path) => path.replace(/^\/v1/, '/v1')
-			}
+export default defineConfig(({mode})=>{
+	const ENV = loadEnv(mode, process.cwd());	
+	return {
+		base:ENV.VITE_APP_BASE_URL, // 若服务器不是将该项目放在根目录的则 需要此设置 和服务器上同名
+		plugins: [
+			vue(),
+			legacy({
+				polyfills: ['es.promise.finally', 'es/map', 'es/set'],
+				modernPolyfills: ['es.promise.finally']
+			})
+		],
+		server: {
+			port: 3000,
+			cors: true,
+			host: '0.0.0.0',
+			proxy: {
+				'/v1': {
+					// target: 'http://8.136.199.33:8608',
+					target: 'https://charttest.hzinsights.com',
+					changeOrigin: true,
+					rewrite: (path) => path.replace(/^\/v1/, '/v1')
+				}
+			},
+		},
+		build: {
+			outDir: 'eta_chart_front',
+			chunkSizeWarningLimit: 1000,//单文件过1000kb警告
 		},
-	},
-  build: {
-    outDir: 'eta_chart_front',
-		chunkSizeWarningLimit: 1000,//单文件过1000kb警告
-  },
-  resolve: {
-		alias: {
-			'@': path.resolve(__dirname, './src')
+		resolve: {
+			alias: {
+				'@': path.resolve(__dirname, './src')
+			},
 		},
-	},
-	css: {
-		postcss: {
-			plugins: [
-				{
-					postcssPlugin: 'internal:charset-removal',
-					AtRule: {
-						charset: (atRule) => {
-							if (atRule.name === 'charset') {
-								atRule.remove()
+		css: {
+			postcss: {
+				plugins: [
+					{
+						postcssPlugin: 'internal:charset-removal',
+						AtRule: {
+							charset: (atRule) => {
+								if (atRule.name === 'charset') {
+									atRule.remove()
+								}
 							}
 						}
 					}
-				}
-			]
+				]
+			}
 		}
 	}
 })