Bläddra i källkod

添加CompressionPlugin gzip压缩

yx 5 år sedan
förälder
incheckning
90c0813b75
2 ändrade filer med 22 tillägg och 1 borttagningar
  1. 1 0
      package.json
  2. 21 1
      vue.config.js

+ 1 - 0
package.json

@@ -36,6 +36,7 @@
     "@vue/cli-service": "^4.3.0",
     "@vue/eslint-config-typescript": "^5.0.2",
     "babel-plugin-component": "^1.1.1",
+    "compression-webpack-plugin": "^4.0.0",
     "eslint": "^6.7.2",
     "eslint-plugin-vue": "^6.2.2",
     "fengmap": "^2.5.3",

+ 21 - 1
vue.config.js

@@ -1,7 +1,8 @@
+const CompressionPlugin = require('compression-webpack-plugin')
 module.exports = {
     devServer: {
         port: 8091,
-        open:true,
+        open: true,
         // 关闭esline
         overlay: {
             warnings: false,
@@ -53,4 +54,23 @@ module.exports = {
     outputDir: 'wandaTopol',
     // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
     assetsDir: 'static',
+    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 删除源文件
+                }),
+            ],
+        }
+    },
 }