.1 下载包
yarn add compression-webpack-plugin@^5
.2 找到 node_modules/react-scripts/webpack.config.js
.3 导入包
constCompressionPlugin=require('compression-webpack-plugin')
.4 搜索 HtmlWebpackPlugin 找到 plugins 在它里面加入
plugins: [
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',//算法
test: /\.js$|\.css$/,
threshold: 10240, // 只处理比这个值大的资源。按字节计算
minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
}),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin(..)
]
.5 打包 然后就能压缩了