webpack-html-inject-plugin
A webpack plugin that inject some variables to entry html.
Usage
First, install webpack-html-inject-plugin
as a development dependency:
npm i -D @forgleaner/webpack-html-inject-plugin
Then, add it to your webpack.config.js
:
const HtmlInjectPlugin = require('webpack-html-inject-plugin');
webpackOptions.plugins.push(new HtmlInjectPlugin({
filename: 'index.html',
data: {
ENV_DEBUG: false,
ENV_DEV: true,
token: 'zawQrZL963RGtXrd2rYmLmUOeckesAaLlYgtNVA89'
}
}));
Before
<script>
window.token = {{token}};
window.ENV_DEBUG = {{ENV_DEBUG}};
window.ENV_DEV = {{ENV_DEV}};
</script>
After
<script>
window.ENV_DEBUG = false;
window.ENV_DEV = true;
window.token = 'zawQrZL963RGtXrd2rYmLmUOeckesAaLlYgtNVA89';
</script>
API
new HtmlInjectPlugin([options])
options
Type: object
filename
Type: String
The file to write the HTML to.
data
Type: object