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
output: { filename: '[name].[hash:8].js', path: __dirname + '/built' }
hash是compilation对象计算所得,而不是具体的项目文件计算所得。所以以上配置的编译输出文件,所有的文件名都会使用相同的hash指纹
hash可以作为版本控制的一环,将其作为编译输出文件夹的名称统一管理
output: { filename: '[name].[chunkhash:8].js', path: __dirname + '/built' }
chunkhash是根据具体模块文件的内容计算所得的hash值,所以某个文件的改动只会影响它本身的hash指纹,不会影响其他文件。
extract-text-webpack-plugin提供了另外一种hash值:contenthash。顾名思义,contenthash代表的是文本文件内容的hash值,也就是只有style文件的hash值
思路:
打包优化:
减小打包体积
extract-text-webpack-plugin
使用CommonsChunkPlugin将公用vendor提取出来
解决:将react,reactdom缓存起来
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: function (module) { // any required modules inside node_modules are extracted to vendor return ( module.resource && /\.js$/.test(module.resource) && module.resource.indexOf( path.join(__dirname, '../node_modules') ) === 0 ) } }), new webpack.optimize.CommonsChunkPlugin({ name: 'manifest' }),
代码压缩
webpack-parallel-uglify-plugin插件可以并行运行UglifyJS插件,这可以有效减少构建时间
webpack-parallel-uglify-plugin
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin'); new ParallelUglifyPlugin({ cacheDir: '.cache/', uglifyJS:{ output: { comments: false }, compress: { warnings: false } } })
The text was updated successfully, but these errors were encountered:
No branches or pull requests
概念:
背景:
自动化构建流程:
自动化工具设计
webpack优势:
缺点:
webpack核心概念
A&Q
hash是compilation对象计算所得,而不是具体的项目文件计算所得。所以以上配置的编译输出文件,所有的文件名都会使用相同的hash指纹
hash可以作为版本控制的一环,将其作为编译输出文件夹的名称统一管理
chunkhash是根据具体模块文件的内容计算所得的hash值,所以某个文件的改动只会影响它本身的hash指纹,不会影响其他文件。
extract-text-webpack-plugin提供了另外一种hash值:contenthash。顾名思义,contenthash代表的是文本文件内容的hash值,也就是只有style文件的hash值
优化
思路:
打包优化:
减小打包体积
extract-text-webpack-plugin
使用CommonsChunkPlugin将公用vendor提取出来
解决:将react,reactdom缓存起来
代码压缩
webpack-parallel-uglify-plugin
插件可以并行运行UglifyJS插件,这可以有效减少构建时间The text was updated successfully, but these errors were encountered: