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