一、compression-webpack-plugin介绍
参考地址:https://v4.webpack.js.org/plugins/compression-webpack-plugin/
一、compression-webpack-plugin的使用,安装插件
| npm install compression-webpack-plugin --save-dev |
复制
二、在 webpack 配置中,require 或 import 引入
| const CompressionPlugin = require('compression-webpack-plugin'); |
复制
三、配置
| |
| |
| |
| |
| |
| |
| |
| |
| |
| module.exports = { |
| plugins: [ |
| new CompressionPlugin( |
| { |
| algorithm: "gzip", |
| test: /\.(js|css)$/, |
| threshold: 10240, |
| deleteOriginalAssets: false, |
| minRatio: 0.8, |
| } |
| ) |
| ] |
| } |
复制
一、terser-webpack-plugin介绍
参考地址:https://v4.webpack.js.org/plugins/terser-webpack-plugin/
一、安装terser-webpack-plugin
| npm install terser-webpack-plugin --save-dev |
复制
二、在 Webpack 配置中引入
| const TerserPlugin = require('terser-webpack-plugin'); |
复制
三、配置
| module.exports = { |
| optimization: { |
| minimizer: [ |
| new TerserPlugin({ |
| |
| extractComments: false, |
| terserOptions: { |
| compress: { |
| drop_console: true, |
| }, |
| output: { |
| comments: false, |
| }, |
| }, |
| }) |
| ] |
| } |
| } |
复制