What is the right way to set a different <base> for dev/staging/production

If you have a template option set to an HTML file then Version 2.x of the plug-in will not perform any substitution.

In this case, you will need to modify @stever's answer as follows:

new HtmlWebpackPlugin({
  ...
  template: './src/index.ejs',
  baseUrl: process.env.NODE_ENV === 'development'?'/':'/app/'
})

and rename your index.html file to index.ejs


the best what I found so far was to put this property in config(HtmlWebpackPlugin option):

new HtmlWebpackPlugin({
  ...
  baseUrl: process.env.NODE_ENV == 'development'?'/':'/app/'
})

and then output it in index.html:

<base href="<%= htmlWebpackPlugin.options.baseUrl %>" />

Tags:

Webpack