Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
webpack使用index.htm中的捆绑哈希替换占位符_Webpack_Html Webpack Plugin - Fatal编程技术网

webpack使用index.htm中的捆绑哈希替换占位符

webpack使用index.htm中的捆绑哈希替换占位符,webpack,html-webpack-plugin,Webpack,Html Webpack Plugin,我的目标是替换像 <!--configjs--> 你想使用 配置插件(我认为您希望将inject设置为false,以提供更好的控制) 在html模板中,按名称调用块 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <script src="<%= html

我的目标是替换像

<!--configjs-->
你想使用

配置插件(我认为您希望将inject设置为false,以提供更好的控制)

在html模板中,按名称调用块

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <script src="<%= htmlWebpackPlugin.files['bundle-hash'].entry %>"></script>
  </head>
  <body>
  </body>
</html>


我不完全确定您的确切需求,但您可能只需要使用插件默认值就可以得到您想要的。该插件可以将现有的html文件作为模板,在头部插入CSS,在身体中插入脚本。如果你想要更多的控制,你可以按照我上面的建议去做。

谢谢@cgatian,但它不起作用。inject:false或inject:true都缺少替换,但我必须设置为“body”来管理脚本标记。我的意思是,如果我偷看html源代码,我仍然看到我已经用我必须使用的当前HtmlWebpackPlugin设置更新了我的帖子
htmlWebpackPlugin.files.chunks.main.entry
。只需将
放入你的html中,自己看看路径应该是怎样的。你知道有哪种网页插件可以像占位符一样用变量替换
html网页插件
,但可以在任意文件上替换?
plugins: [
    // Injects bundles in your index.html instead of wiring all manually.
    // It also adds hash to all injected assets so we don't have problems
    // with cache purging during deployment.
    new HtmlWebpackPlugin({
      template: 'client/index.html',
      inject: 'body',
      hash: true
    })
]
// webpack.config.js
plugins: [new HtmlWebpackPlugin(
    {
       inject : false,
       template : 'index.html'
    }
)]
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <script src="<%= htmlWebpackPlugin.files['bundle-hash'].entry %>"></script>
  </head>
  <body>
  </body>
</html>