Javascript 如何在html标题中使用webpack哈希?
我对webpack很新鲜,我的webpack.config.js:Javascript 如何在html标题中使用webpack哈希?,javascript,html,webpack,html-webpack-plugin,Javascript,Html,Webpack,Html Webpack Plugin,我对webpack很新鲜,我的webpack.config.js: 插件:[ 新HtmlWebpackPlugin({ 哈什:没错, templateParameters:{title:'[name].[contenthash]'}, 是的, }), ], 在my index.ejs中: <title><%= title %></title> 但在my out/index.html中,标题仅为: <title>[name].[conten
插件:[
新HtmlWebpackPlugin({
哈什:没错,
templateParameters:{title:'[name].[contenthash]'},
是的,
}),
],
在my index.ejs中:
<title><%= title %></title>
但在my out/index.html中,标题仅为:
<title>[name].[contenthash]</title>
[name].[contenthash]
期望:
<title>app.7472b25c2ed347463dbc</title>
app.7472b25c2ed347463dbc
如何修复它?2020-11-13更新
最后,我发现可以像这样使用全局变量:webpack\u hash:
我们可以直接在index.ejs中使用它,而无需在webpack.config.js中执行任何操作
初始版
webpack.config.js:
插件:[
新HtmlWebpackPlugin({
//1.title是参数,可以在ejs模板中使用
模板参数:{
标题:JSON.stringify(someting:'something'),
},
}),
//2.Build_AT也是一个参数,可以使用。
新的webpack.DefinePlugin({
构建地址:webpack.DefinePlugin.runtimeValue(Date.now,“some”),
}),
//3.对于webpack5,您可以使用全局变量:\ uu webpack\ uHash__
//新的webpack.ExtendedAPIPlugin()
],
//4. 这不是变量,这是模块,所以使用“import tt”来使用它。
外部:{
“ex_title”:JSON.stringify({
tt:‘EIT’,
})
},