From 92ec662c7f19449f906a7e7a10addb4c87a27837 Mon Sep 17 00:00:00 2001 From: "lily.zhang" Date: Fri, 22 Oct 2021 12:58:56 +0800 Subject: [PATCH] cxw-010203 --- package.json | 1 + vue.config.js | 30 +++++++++++++++++++++++++++--- yarn.lock | 28 ++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 600bff7..d1d0111 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@jiaminghi/data-view": "^2.10.0", "ant-design-vue": "^1.7.8", "axios": "^0.23.0", + "compression-webpack-plugin": "^9.0.0", "core-js": "^3.6.5", "echarts": "^5.2.1", "less": "^4.1.2", diff --git a/vue.config.js b/vue.config.js index 4fd4e8b..d36f139 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,13 +1,15 @@ /* * @Author: your name * @Date: 2021-10-20 13:15:16 - * @LastEditTime: 2021-10-22 09:24:06 + * @LastEditTime: 2021-10-22 12:55:30 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /data-show/vue.config.js */ - +const CompressionWebpackPlugin = require('compression-webpack-plugin') +const productionGzipExtensions = ['js', 'css', 'svg'] module.exports = { + productionSourceMap: false, publicPath: "./", devServer: { port: "8081", @@ -21,6 +23,28 @@ module.exports = { } } } - } + }, + configureWebpack: config => { + if (process.env.NODE_ENV === 'production') { + // 配置productionGzip-高级的方式 + // 配置参数详解 + // asset: 目标资源名称。 [file] 会被替换成原始资源。[path] 会被替换成原始资源的路径, [query] 会被替换成查询字符串。默认值是 "[path].gz[query]"。 + // algorithm: 可以是 function(buf, callback) 或者字符串。对于字符串来说依照 zlib 的算法(或者 zopfli 的算法)。默认值是 "gzip"。 + // test: 所有匹配该正则的资源都会被处理。默认值是全部资源。 + // threshold: 只有大小大于该值的资源会被处理。单位是 bytes。默认值是 0。 + // minRatio: 只有压缩率小于这个值的资源才会被处理。默认值是 0.8。 + config.plugins.push( + new CompressionWebpackPlugin({ + filename: '[path].gz[query]', + algorithm: 'gzip', + test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), + threshold: 10240, + minRatio: 0.8 + }) + ) + } else { + // 开发环境 + } + } } diff --git a/yarn.lock b/yarn.lock index c004b55..dabef2e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1104,7 +1104,7 @@ dependencies: "@types/node" "*" -"@types/json-schema@^7.0.5": +"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8": version "7.0.9" resolved "https://registry.nlark.com/@types/json-schema/download/@types/json-schema-7.0.9.tgz?cache=0&sync_timestamp=1629708189890&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fjson-schema%2Fdownload%2F%40types%2Fjson-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" integrity sha1-l+3JA36gw4WFMgsolk3eOznkZg0= @@ -1682,7 +1682,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1, ajv-keywords@^3.5.2: resolved "https://registry.nlark.com/ajv-keywords/download/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" integrity sha1-MfKdpatuANHC0yms97WSlhTVAU0= -ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.3, ajv@^6.12.4: +ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.5: version "6.12.6" resolved "https://registry.nlark.com/ajv/download/ajv-6.12.6.tgz?cache=0&sync_timestamp=1631470912358&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fajv%2Fdownload%2Fajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha1-uvWmLoArB9l3A0WG+MO69a3ybfQ= @@ -2733,6 +2733,14 @@ compressible@~2.0.16: dependencies: mime-db ">= 1.43.0 < 2" +compression-webpack-plugin@^9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-9.0.0.tgz#38b4e18313f5d704c453ab5645e38a5805ba5889" + integrity sha512-V2KmQqaUkErPT+ZcUGHa8zWpIw1oTYaC7wjGewJm053GWAoY04GfU5B/NZ/JSz1eFp9MggMdLQpEHe1TJAQY1A== + dependencies: + schema-utils "^3.1.0" + serialize-javascript "^6.0.0" + compression@^1.7.4: version "1.7.4" resolved "https://registry.nlark.com/compression/download/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f" @@ -7429,6 +7437,15 @@ schema-utils@^2.0.0, schema-utils@^2.5.0, schema-utils@^2.6.5, schema-utils@^2.7 ajv "^6.12.4" ajv-keywords "^3.5.2" +schema-utils@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" + integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + select-hose@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/select-hose/download/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" @@ -7482,6 +7499,13 @@ serialize-javascript@^4.0.0: dependencies: randombytes "^2.1.0" +serialize-javascript@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" + integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== + dependencies: + randombytes "^2.1.0" + serve-index@^1.9.1: version "1.9.1" resolved "https://registry.npm.taobao.org/serve-index/download/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239"