HtmlWebpackPlugin insert dynamic value

Developer from somewhere

Problem: add a value in index.html depending on a condition

Solution:

  • modify webpack file, to have this ( notice the someValue key ):
new HtmlWebpackPlugin({
      someValue: someValue,
      filename: 'index.html',
    }),
  • then modify index.html with your logic, and make use of the value, like in the following snippet:
<%=  htmlWebpackPlugin.options.someValue %>