Search⌘ K

Building for Different Environments

Explore how to set up and manage multiple environment configurations in Angular apps. Understand how to create environment files, configure the Angular CLI for different builds, and include external assets and libraries in your project. This lesson prepares you to build and deploy Angular applications optimized for development, staging, and production environments.

An organization may want to build an Angular application for multiple environments that require different variables, such as a backend API endpoint and application local settings. A common use case is a staging environment for testing the application before deploying it to production.

The Angular CLI enables us to define different configurations for each environment and build our application with each one. We can execute the ng build command (for a local machine) while passing the configuration name as a parameter using the following syntax:

ng build --configuration=name
Passing the configuration as a parameter in the ng build command

Note: We can also pass a configuration in other Angular CLI commands, such as ng serve and ng test.

Creating environment files in the application

The first thing we need to do ...