diff --git a/.env b/.env
new file mode 100644
index 0000000..1b7786e
--- /dev/null
+++ b/.env
@@ -0,0 +1,3 @@
+# 请求api地址:process.env.VUE_APP_URL
+VUE_APP_URL=http://localhost:8088/xxx
+VUE_APP_FLAG = 'prod'
diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000..c20c746
--- /dev/null
+++ b/.env.development
@@ -0,0 +1,3 @@
+# 请求api地址:process.env.VUE_APP_URL
+VUE_APP_URL=http://localhost:8088/xxx
+VUE_APP_FLAG = 'dev'
diff --git a/.env.test b/.env.test
new file mode 100644
index 0000000..c8d5f43
--- /dev/null
+++ b/.env.test
@@ -0,0 +1,4 @@
+NODE_ENV = 'production'
+# 请求api地址:process.env.VUE_APP_URL
+VUE_APP_URL=http://localhost:8088/xxx
+VUE_APP_FLAG = 'test'
diff --git a/package.json b/package.json
index 0c93460..d515a25 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
+ "testbuild": "vue-cli-service build --mode test",
"lint": "vue-cli-service lint",
"lint:eslint": "eslint --fix --ext .js,.ts,.vue ./src",
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,ts,json,tsx,css,less,scss,vue,html,md}\"",
diff --git a/public/index.html b/public/index.html
index 3e5a139..a1a3aa0 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3,7 +3,7 @@
-
+
<%= htmlWebpackPlugin.options.title %>
diff --git a/src/router/index.ts b/src/router/index.ts
index 08baa11..44674b8 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -1,4 +1,4 @@
-import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router';
+import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
const routes: Array = [
{
@@ -13,7 +13,8 @@ const routes: Array = [
* 如果不需要 createWebHistory
*/
const router = createRouter({
- history: createWebHashHistory(process.env.BASE_URL),
+ history:
+ process.env.NODE_ENV === 'production' ? createWebHashHistory(process.env.BASE_URL) : createWebHashHistory(process.env.BASE_URL),
routes,
});
diff --git a/src/views/layout.vue b/src/views/layout.vue
index 5257ab6..71d47b7 100644
--- a/src/views/layout.vue
+++ b/src/views/layout.vue
@@ -1,5 +1,5 @@
- 成功
+ 成功
diff --git a/vue.config.js b/vue.config.js
index 0516ca6..b55ae39 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -2,6 +2,31 @@ const { defineConfig } = require('@vue/cli-service');
const WebpackBar = require('webpackbar');
module.exports = defineConfig({
transpileDependencies: true,
+ productionSourceMap: false, // 不生成map文件-优化打包
+ // 生产环境,开启js\css压缩--- 打包优化
+ chainWebpack: config => {
+ if (process.env.NODE_ENV === 'production') {
+ config.plugin('compressionPlugin').use(
+ new CompressionPlugin({
+ test: /\.(js|css|less|map)$/, // 匹配文件名
+ threshold: 1024, // 对超过10k的数据压缩
+ minRatio: 0.8,
+ }),
+ );
+ }
+ },
+ // 代理设置
+ devServer: {
+ port: 6366,
+ open: true,
+ https: false,
+ proxy: {
+ '/api': {
+ target: process.env.VUE_APP_URL,
+ changeOrigin: true,
+ },
+ },
+ },
configureWebpack: {
plugins: [
// 设置进度条颜色