Angular Version 7: One way to include some environment-specific js is to
save the script in some way: For example: src/assets/javascripts/prod.js
Then, in angular.json find the build configuration for the specific configuration (see: here ) and in the desired environment add an additional array of scripts.
ng build --prod will also bundle an additional script.
The example below uses the production environment for demonstration, but this can be done for any environment.
Sample angular.json below. Tested on Angular 7 (Please refer only to the "scripts" key inside the assembly configuration, the file has been changed a lot to show only the corresponding part)
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "test": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": {}, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": {}, "configurations": { "production": { "scripts": ["src/assets/javascripts/prod.js"] } } } } } }, "defaultProject": "test" }
source share