[英]How to replace placeholders for environment variables in static `index.html` to actual values with brunch?
I use brunch for compilation of static assets. 我使用早午餐来编译静态资产。 I've an
index.html
containing a <script>
tag with environment variable placeholders. 我有一个
index.html
其中包含带有环境变量占位符的<script>
标记。 Based on the environment I want to change the placeholders to actual values. 根据环境,我想将占位符更改为实际值。 How can I do it the simplest way using brunch?
如何使用早午餐最简单的方法?
I tried several plugins, but although sounds to be a simple task, I fail to get anything replaced. 我尝试了几个插件,但是虽然听起来很简单,但是我无法替换任何东西。
You can install handlebars-brunch
plugin from master
, add 您可以从
master
安装handlebars-brunch
插件,添加
handlebars: {
locals: {
env: process.env
}
}
to plugins
in brunch-config.js
, rename index.html
to index.html.hbs
and use it like this: 到
brunch-config.js
plugins
,将index.html
重命名为index.html.hbs
并像这样使用它:
<script>
alert("{{env.key}}")
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.