Our application is expanding with multiple environments and vendors on the horizon. While the traditional approach of running
webpack --env.NODE_ENV=myenvironment
works for now, it will soon become inefficient.
The main objective here is to streamline the process by simply copying the environment.json
file into the output folder. This way, I can handle transformations in Octopus Deploy without the need for multiple builds.
Essentially, I want to use a single environment.json
file for variable substitutions in Octopus Deploy. Here's a peek at what that might look like:
{
"production": false,
"baseUrl": "http://myapp.com",
"appId": "MyAppId"
}
In my AngularJS code, I'm setting up constants based on these values:
import * as environment from '../../environment.json';
console.log(environment.baseUrl); // http://myapp.com
angular.module('app')
.constant('environment', environment);
Seems straightforward so far.
The issue arises when I make changes within the dist/environment.json
file (located in the output folder) and those updates don't get reflected. For instance, if I update the value of baseUrl
to http://myapp-dev.com
, the console still shows http://myapp.com
.
Here's a snippet of code from my webpack.config.js
:
Rules
...
{
test: /\.json$/,
use: 'json-loader',
exclude: [/environment\.json$/]
},
...
Plugins
...
new CopyWebpackPlugin([{
from: 'environment.json'
},
...
While this code successfully copies the environment.json
file to the output folder, the other files there seem unaffected. It seems like they are still tied to webpack somehow.