如何在 html-webpack-plugin 中使用 ./ 而不是 / bundle src 构建 index.html

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

我的 html-webpack-plugin 构建了一个 index.html 与 bundle src to /main[hash].html

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

如何在 src url 的开头使用 ./ 构建 index.html?像这样:

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

添加一个publicPath setting to your output configuration. See https://github.com/jantimon/html-webpack-plugin/issues/694以获得更完整的示例;在你的情况下,你可能想要在你的 webpack 配置中这样的东西:

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