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

1k views Asked by At

I use brunch for compilation of static assets. I've an index.html containing a <script> tag with environment variable placeholders. 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.

1

There are 1 answers

2
Alexey Shvayka On BEST ANSWER

You can install handlebars-brunch plugin from master, add

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

to plugins in brunch-config.js, rename index.html to index.html.hbs and use it like this:

<script>
    alert("{{env.key}}")
</script>