What I want to achieve?
Generating Environments variable depending on which NODE_ENV I am currently compiling on an Ejected project (ng eject).
The same of targeting the environment using the Angular Cli:
ng build --prod || ng build --dev
.
What I tried?
- Setting my NODE_ENV in my scripts:
package.json
...
"start": "NODE_ENV=development webpack-dev-server --port=4200",
"start:prod": "NODE_ENV=production webpack-dev-server --port=4200",
...
As suggested here, I changed my AotPlugin in webpack and replace it with:
const environmentFiles = { 'development': 'environments/environment.dev.ts', 'production': 'environments/environment.prod.ts', }; ... new AotPlugin({ ... "hostReplacementPaths": "environments/environment.ts": environmentFiles[process.env.NODE_ENV]
- Try to run: npm run-script build:prod But the AotPlugin doesn't look to replace (hostReplacementPaths) for me the Environment variables file (environment.dev.ts || environment.prod.ts).
Any idea?
Similiar questions:
Environment file replacement is broken after switching to webpack...