We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack.config.js
const UglifyWebpackPlugin = require('uglifyjs-webpack-plugin'); module.exports = { optimization: { minimizer: [ new UglifyWebpackPlugin({ parallel: 4 }) ] } }
使用terser-webpack-plugin来压缩js文件,替换掉之前的 uglifyjs-webpack-plugin,解决uglifyjs不支持es6语法问题
const TerserPlugin = require('terser-webpack-plugin'); module.exports = { plugins: [ new TerserPlugin({ parallel: true, // parallel 代表开启多进程 cache: true // 代表设置缓存 }), ], };
使用 optimize-css-assets-webpack-plugin 来压缩 css 文件。
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin'); module.exports = { optimization: { minimizer: [ new OptimizeCssAssetsWebpackPlugin() ] } }
OptimizeCSSAssetsPlugin 中加载了一个 cssnano 的东西, cssnano 是 PostCSS 的 CSS 优化和分解插件,会自动采用格式很好的 CSS,并通过许多优化,以确保最终的生产环境尽可能小。
可以利用 copy-webpack-plugin 这个插件将文件拷贝到目标目录下
const CopyPlugin = require('copy-webpack-plugin'); module.exports = { plugins: [ new CopyPlugin([ { from: 'source', to: 'dest' }, { from: 'other', to: 'public' }, ]), ], };
const {CleanWebpackPlugin} = require('clean-webpack-plugin'); module.exports = { plugins: [ new CleanWebpackPlugin() ] }
不是很建议这么使用,一般是在build命令前加rm -rf dist && webpack
rm -rf dist && webpack
代码改动,动态局部加载 HMR(模块热替换)
webpack自带的插件HotModuleReplacementPlugin、NamedModulesPlugin
const webpack = require('webpack'); module.exports = { plugins: [ new webpack.NamedModulesPlugin(), // webpack自带的插件 以便查看修补patch依赖 new webpack.HotModuleReplacementPlugin() ] }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
压缩JS文件
uglifyjs-webpack-plugin
webpack.config.js
terser-webpack-plugin
webpack.config.js
压缩CSS文件
使用 optimize-css-assets-webpack-plugin 来压缩 css 文件。
webpack.config.js
OptimizeCSSAssetsPlugin 中加载了一个 cssnano 的东西, cssnano 是 PostCSS 的 CSS 优化和分解插件,会自动采用格式很好的 CSS,并通过许多优化,以确保最终的生产环境尽可能小。
拷贝静态文件
可以利用 copy-webpack-plugin 这个插件将文件拷贝到目标目录下
webpack.config.js
打包前先清空输出目录
热加载
代码改动,动态局部加载 HMR(模块热替换)
webpack自带的插件HotModuleReplacementPlugin、NamedModulesPlugin
The text was updated successfully, but these errors were encountered: