Explorar o código

开启gzip压缩

yx %!s(int64=4) %!d(string=hai) anos
pai
achega
920a6c5837
Modificáronse 2 ficheiros con 22 adicións e 0 borrados
  1. 1 0
      package.json
  2. 21 0
      vue.config.js

+ 1 - 0
package.json

@@ -45,6 +45,7 @@
         "@vue/eslint-config-typescript": "^5.0.2",
         "babel-eslint": "^10.0.3",
         "babel-plugin-component": "^1.1.1",
+        "compression-webpack-plugin": "^4.0.0",
         "cross-env": "^7.0.2",
         "eslint": "^5.16.0",
         "eslint-plugin-vue": "^5.0.0",

+ 21 - 0
vue.config.js

@@ -1,3 +1,4 @@
+const CompressionPlugin = require('compression-webpack-plugin')
 module.exports = {
     devServer: {
         port: 8090,
@@ -63,6 +64,8 @@ module.exports = {
             .end()
             .use('vue-svg-loader')
             .loader('vue-svg-loader')
+        config.output.filename('static/js/[name].[hash].js').end()
+        config.output.chunkFilename('static/js/[name].[hash].js').end()
     },
     lintOnSave: false,
     publicPath: '/wandaBmGuide',
@@ -76,4 +79,22 @@ module.exports = {
         "element-ui"
     ],
     productionSourceMap: false, //
+    // CSS 相关选项
+    css: {
+        // 将组件内的 CSS 提取到一个单独的 CSS 文件 (只用在生产环境中)
+        extract: true,
+    },
+    // 配置webpack
+    configureWebpack: (config) => {
+        return {
+            plugins: [
+                // 压缩代码
+                new CompressionPlugin({
+                    test: /\.js$|\.html$|.\css/, // 匹配文件名
+                    threshold: 10240, // 对超过10k的数据压缩
+                    deleteOriginalAssets: false, // true 不删除源文件 false 删除源文件
+                }),
+            ],
+        }
+    },
 }