replace-webpack-plugin
Webpack Plugin to replace blocks in HTML.
Install
npm i --save replace-webpack-plugin
To replace html content with provided string, just wrap your content with comment like this:
<!-- replace:[name] --> blocks you want to replace<!-- endreplace -->
API
- skip
Boolean
if true - original content will be left (default false) - entry
String
original file - output
String
new file with replaced data - data
Object
key-value pair of block identifier and new string - hash
String
string that should be replaced by webpack entry hash
Example
//webpack.config.jsvar ReplacePlugin = ;var config = ... plugins: skip: processenvNODE_ENV === 'development' entry: 'index.html' hash: '[hash]' output: '/build/index.html' data: css: '<link type="text/css" rel="stylesheet" href="styles.css">' js: '<script src="bundle.js"></script>' ...;moduleexports = config;
<!-- index.html --> <!-- replace:css --> <!-- endreplace --> replace-webpack-plugin <!-- replace:js --> <!-- endreplace -->
result:
<!-- build/index.html --> replace-webpack-plugin
Thanks to @VFK for the regexp