html-webpack-plugin and webpack 2: no starting slash '/'

我与影子孤独终老i 提交于 2020-01-13 19:08:13

问题


I have a working webpack 1 project that I want to migrate to webpack 2.

It is almost working, my main remaining problem is with html-webpack-plugin:

when I use it in webpack 2, the generated script tag is of the form:

<script type="text/javascript" src="static/js/bundle.js"></script>

instead of:

<script type="text/javascript" src="/static/js/bundle.js"></script>

Note: with the same plugin options, it works as expected in Webpack 1.

Here are the relevant parts of webpack conf:

  entry: [
    paths.appIndexJs,
    publicPath,
  ],
  output: {
    pathinfo: true,
    path: paths.appBuild,
    filename: 'static/js/bundle.js',
  },

  // (...)

  plugins: [
    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml,
    }),

What am I doing wrong?


回答1:


Try setting output.publicPath explicitly:

output : {
  filename   : 'static/js/bundle.js',
  path       : paths.appBuild,
  publicPath : '/'
}


来源:https://stackoverflow.com/questions/43191569/html-webpack-plugin-and-webpack-2-no-starting-slash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!