Webpack - How to replace file reference based on environment?

Viewed 227

In the angular-cli tool, environment files are present. You can specify them in your config file, like:

"environmentSource": "environments/environment.ts",
"environments": {
  "dev": "environments/environment.ts",
  "prod": "environments/environment.prod.ts"
}

Anywhere in your project where you want to use the environment variables, all you have to do is include the base environment.ts file. Then, based on the build environment you can pass e.g. using ng build --prod, the file reference may change (so for prod, it will use environment.prod.ts instead of environment.ts).

I'm trying to achieve the same functionality through Webpack configuration, but can't figure out how to achieve this.

Anyone who can give an example on how to configure such dynamic file reference based on environments in Webpack?

Thanks!

0 Answers
Related