From f8cbdcf4667558cdf6d3f1382012efb29c064025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E6=A3=9A?= <849005670@qq.com> Date: Fri, 3 Dec 2021 16:06:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8C=85=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/webpack.config.js | 13 +++++++-- package-lock.json | 59 ++++++++++++++++++++++++++++++++++++++++ package.json | 11 ++++---- scripts/test.js | 4 +-- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/config/webpack.config.js b/config/webpack.config.js index 7e4eb228..53bb452e 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -30,10 +30,10 @@ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin' const postcssNormalize = require('postcss-normalize'); const appPackageJson = require(paths.appPackageJson); - +const CompressionPlugin = require("compression-webpack-plugin"); // Source maps are resource heavy and can cause out of memory issue for large source files. -const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; -// const shouldUseSourceMap = false; +// const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; +const shouldUseSourceMap = false; const webpackDevClientEntry = require.resolve( 'react-dev-utils/webpackHotDevClient' ); @@ -597,6 +597,13 @@ module.exports = function (webpackEnv) { ], }, plugins: [ + new CompressionPlugin({ + filename: '[path].gz[query]', // 目标资源名称。[file] 会被替换成原资源。[path] 会被替换成原资源路径,[query] 替换成原查询字符串 + algorithm: 'gzip', // 算法 + test: new RegExp('\\.(js|css)$'), // 压缩 js 与 css + threshold: 550, // 只处理比这个值大的资源。按字节计算 + minRatio: 0.8 // 只有压缩率比这个值小的资源才会被处理 + }), // Generates an `index.html` file with the