html-webpack-plugin 和 webpack 2:没有起始斜杠“/" [英] html-webpack-plugin and webpack 2: no starting slash '/'

查看:34
本文介绍了html-webpack-plugin 和 webpack 2:没有起始斜杠“/"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的 webpack 1 项目,我想将其迁移到 webpack 2.

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

它几乎可以工作了,我剩下的主要问题是 html-webpack-plugin:

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

当我在 webpack 2 中使用它时,生成的脚本标签是这样的:

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>

代替:

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

注意:使用相同的插件选项,它在 Webpack 1 中按预期工作.

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

以下是 webpack conf 的相关部分:

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,
    }),

我做错了什么?

推荐答案

尝试显式设置 output.publicPath:

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

这篇关于html-webpack-plugin 和 webpack 2:没有起始斜杠“/"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆