簡體   English   中英

如何用早午餐將靜態index.html中環境變量的占位符替換為實際值?

[英]How to replace placeholders for environment variables in static `index.html` to actual values with brunch?

我使用早午餐來編譯靜態資產。 我有一個index.html其中包含帶有環境變量占位符的<script>標記。 根據環境,我想將占位符更改為實際值。 如何使用早午餐最簡單的方法?

我嘗試了幾個插件,但是雖然聽起來很簡單,但是我無法替換任何東西。

您可以從master安裝handlebars-brunch插件,添加

handlebars: {
  locals: {
    env: process.env
  }
}

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