如下例子,期望替换 html 中 type 的内容,该如何设置呢?
如下test.html内容:
<head>
<title></title>
</head>
<body>
<script>
window.type = '<%="<"%>%type%<%=">"%>';
window.buildTime = <%= buildTime %>;
</script>
</body>
</html>
webpack相关的配置如下:
new HtmlWebpackPlugin({
template: 'test.html',
templateParameters: {
buildTimestamp: Number(new Date())
}
})
用
templateContent
代替template
和templateParameters
。先用正则替换完变量再通过templateContent
传给插件。