简体   繁体   English

如何用早午餐将静态index.html中环境变量的占位符替换为实际值?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM