title: Aurelia Webpack Use Environment Variables In index.ejs and/or webpack.config.js
body: <p>I have created an application that makes use of Google services. In order to properly lock down my API keys, I have restricted their use depending on the machine from where they are operating. With these restrictions, I have needed to create a separate development API key. The problem being that I now need to switch between which key my Aurelia app is using on build such that using <code>au build --env dev</code> will use the development Google API key and <code>au build --env prod</code> will use the production Google API key.</p>
  
  <p>I'm rather familiar with adding environment variables in the <code>aurelia_project/environments/x.js</code> and using them in my <code>.js</code> classes via injection, however as Google script tags are found in the <code>index.ejs</code> file, I am unable to figure out how to get them in here.</p>
  
  <p>E.g. In <code>index.ejs</code></p>
  
  <pre><code>&lt;script src="https://maps.googleapis.com/maps/api/js?key=&lt;key binding here&gt;&amp;libraries=places"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I notice there is a binding syntax in this same file of
  <code>&lt;%- htmlWebpackPlugin.options.metadata.property_name&gt;%&gt;</code> which gets its value from the <code>webpack.config.js</code> file and I understand how it is made available via plugins namely</p>
  
  <pre><code>plugins: [
      ...
      new HtmlWebpackPlugin({
        template: 'index.ejs',
        metadata: {
          // available in index.ejs //
          title, server, baseUrl //&lt;- new property here
        }
      }),
  </code></pre>
  
  <p>But this still begs the question: How do I make this file aware of environment variables?</p>
  
  <p><strong>Extra information:</strong> I've tried moving the script tag to the <code>app.html</code> file but get loads of undefined errors on Google services, so it looks like I'm deeply restricted to having the script tag in the <code>index.ejs</code> file.</p>
  
  <p>Thanks for the help!</p>