Webpack plugin for transforming js bundle references in your html files with cache friendly filenames using chunkhashes.
npm install chunkhash-replace-dm-webpack-pluginChunkhash Replace Webpack Plugin
================================
This plugin is for transforming bundle references in your html files with cache friendly filenames using chunkhashes. Its main use is for processing js file references. CSS files will work too, but chunkhashes are associated with js bundles, so changes to your css will not generate a new chunkhash. For handling CSS bundles I recommend the Content Hash Replace Plugin.
Tip: Just use this plugin for your production/staging builds.
shell
$ npm install chunkhash-replace-dm-webpack-plugin --save-dev
`
Example
$3
`javascript
const path = require('path');
const ChunkHashReplacePlugin = require('chunkhash-replace-dm-webpack-plugin');
module.exports = env => {
entry: {
app: ['./src/app.js'],
vendor: ['jquery', 'lodash', 'react', 'react-dom']
},
output: {
path: path.join(__dirname, 'dist/static'),
filename: scripts/[name]${env.prod?'.[chunkhash]':''}.bundle.js,
publicPath: '/static/'
},
plugins: [
new ChunkHashReplacePlugin({
src: 'index.html',
dest: 'dist/index.html',
})
]
};
`
$3
To run on production mode set extra param --env.prod
Environment Variables | webpack
`shell
webpack --config webpack.config.js --env.prod
`
For dev mode you don't need to do chunkhash is faster
`shell
webpack --config webpack.config.js
`
$3
filename:
- [name].[chunkhash].js
- scripts/[name].[chunkhash].js
- scripts/[name].[chunkhash].bundle.js
- scripts/[name]${env.prod?'.[chunkhash]':''}.bundle.js
$3
`html
`
$3
`html
``