Search code examples
html-webpack-plugin

How build index.html with ./ instead of / bundle src in html-webpack-plugin


My html-webpack-plugin builds a index.html with bundle src to /main[hash].html

<script type="text/javascript" src="/main.dde2e5563b4d5cd56173.js"></script>

How to make it build index.html with ./ at the beginning of the src url? Like so:

<script type="text/javascript" src="./main.dde2e5563b4d5cd56173.js"></script>

Solution

  • Add a publicPath setting to your output configuration. See https://github.com/jantimon/html-webpack-plugin/issues/694 for a more complete example; in your case you probably want something like this in your webpack config:

    module.exports = {
      // …
      output: {
        // …
        publicPath: '.'
      },
      //…
    }