I'm developing an react.js application, where I provide the index.html file in the public directory, but use webpack to replace placeholders (<%= placeholder %>) in it. Currently, the target strings are provided by options.json, which looks like:
{
"placeholder": "value"
}
I can make it work rudimentarily with the following entry in package.json and the following relevant parts of the webpack.config.js
"scripts": {
"build": "webpack --config=webpack.config.js --env env=production"
}
and
var options = require('./options.json')
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
[...]
plugins: [
new HtmlWebpackPlugin({
template: "public/index.html",
templateParameters: options
})
]
}
My goal would be to run npm run build <user_provided_options.json> so that I can switch between different versions of values for the placeholders. How can I achieve that?