使用 mini-css-extract-plugin 插件的内置loader 替换 style-loader
使用 terser-webpack-plugin 插件压缩js代码
使用 optimize-css-assets-webpack-plugin 插件压缩css代码
const MiniCSSExtractPlugin = require('mini-css-extract-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin'); module.export = { // ... module: { rules: [ { test: /\.css/, loader: [ MiniCSSExtractPlugin.loader, // 替换 style-loader 'css-loader', 'postcss-loader', // autoprefixer ], } ] }, plugins: [ new MiniCSSExtractPlugin({ filename: 'css/main.[contentHash:8].css' }) ], optimization: { minimizer: { // 压缩js new TerserPlugin(), // 压缩css new OptimizeCssAssetsWebpackPlugin() } } }
标签:插件,plugin,压缩,Webpack,抽离,loader,webpack,css From: https://www.cnblogs.com/shaoyunfeng93/p/16731136.html