'How to create environment dependent variables on window with webpack?
I want to have custom variables on window. For example window.apiurl. It's different for dev, and prod. I have two different webpack configs for dev, and prod.
I've tried injecting a script to an .ejs template (<%= window.apiurl = htmlWebpackPlugin.config.apiurl) %>), and defined custom variables on HtmlWebpackPlugin, it didn't work (window is not defined). I tried ProvidePlugin, and DefinePlugin, didn't work. My best shot so far is having two different entry js files for the two different webpack configs. But there must be a more straightforward way to do this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
