- 压缩
CSS
使用 webpack 插件 css-minimizer-webpack-plugin,需要额外安装npm i css-minimizer-webpack-plugin@latest -D
; - 压缩
js
使用 webpack 自带插件 terser-webpack-plugin,无需额外安装; package.json
的配置如下
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");module.exports = {optimization: {// 优化minimize: true,minimizer: [new CssMinimizerPlugin(),//压缩cssnew TerserPlugin({// 压缩 jsterserOptions: {format: {comments: false,},},extractComments: false,}),],}
}