Browse Source

增加打包压缩
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
6464548129
2 changed files with 18 additions and 11 deletions
  1. 2 1
      package.json
  2. 16 10
      vue.config.js

+ 2 - 1
package.json

@@ -13,6 +13,7 @@
     "vue": "^2.6.11"
   },
   "devDependencies": {
-    "@vue/cli-service": "~5.0.8"
+    "@vue/cli-service": "~5.0.8",
+    "compression-webpack-plugin": "^10.0.0"
   }
 }

+ 16 - 10
vue.config.js

@@ -1,3 +1,4 @@
+const CompressionPlugin = require('compression-webpack-plugin');
 module.exports = {
     publicPath: './',
     outputDir: './www',
@@ -8,15 +9,20 @@ module.exports = {
     devServer: {
         https: false,
         port: 4562
-        // proxy: {
-        //     '/api': {
-        //         // 此处的写法,目的是为了 把上面  /api 替换成 http://127.0.0.1:3000/
-        //         // 如果使用的是自己封装的请求函数 那么你应该这样写 baseURL: '',
-        //         // 注意这里的 api 是必须的,因为是有代理的缘故
-        //         target: 'https://caner.top',
-        //             // 允许跨域
-        //         changeOrigin: true
-        //     }
-        // }
+    },
+    configureWebpack: () => {
+        if (process.env.NODE_ENV === 'production') {
+            return {
+                plugins: [
+                    new CompressionPlugin({
+                        minRatio: 1, // 压缩率小于1才会压缩
+                        test: /\.js$|.html$|\.css$/, // 匹配文件名
+                        threshold: 10240, // 对超过10k的文件进行压缩
+                        deleteOriginalAssets: false // 是否删除原文件                        
+                    })
+                ]
+            }
+        }
     }
+
 }