hash
On behalf ofcompilation
thehash
Value.compilation
Any file changes in the project will be recreated and thenwebpack
Calculate the newcompilation
thehash
Value.chunkhash
On behalf ofchunk
thehash
, the module is regenerated only when it changeshash
.contenthash
To solve the changestyle
The file injs
File regenerationhash
The problem of usingextract-text-webpack-plugin
Separate compiled outputcss
File).
The example of vue – cli
Vue – cli scaffolding webpack build configuration file/webpack base. Conf. Js
In vue-CLI, hash is used for image, audio, video, and font files.
// hash(hash,jpg,mo4,txt){ test: /\.(png|jpe? g|gif|svg)(\? . *)? $/, loader:'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\? . *)? $/, loader:'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]') } }, { test: /\.(woff2? |eot|ttf|otf)(\? . *)? $/, loader:'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } }) { test: /\.(png|jpe? g|gif|svg)(\? . *)? $/, loader:'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\? . *)? $/, loader:'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]') } }, { test: /\.(woff2? |eot|ttf|otf)(\? . *)? $/, loader:'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')}}Copy the code
Chunkhash is mainly used in JS files
AssetsPath (‘ js/[name].[chunkhash].js’), chunkFilename: Utils. AssetsPath (‘ js / [id]. [chunkhash] js’)
Note:
chunkhash
It can only be used in production environments but not in development environments.- Remove hot updates, don’t let
webpack.HotModuleReplacementPlugin()
inplugins
In the run,
Hot update andjs
thechunkhash
There are conflicts.
Contenthash: build/webpack. Prod. Conf. Js
Use extract-text-webpack-plugin to compile the output CSS file separately. Extract-text-webpack-plugin provides another hash value: contenthash
// extract css into its own file
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css')}),Copy the code