If I'm understanding your question correctly, have you looked into Angular2 CLI's environment files?
ng build
can specify both a build target (--target=production
or
--target=development
) and an environment file to be used with that build (--environment=dev
or --environment=prod
). By default, the
development build target and environment are used.
The mapping used to determine which environment file is used can be
found in angular-cli.json:
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Static Solution
Modifying these files with the values you needed in each will incorporate them into each respective build, at build-time.
For example, an environment.dev.ts might look like this:
export const environment = {
production: false,
apiUrl: 'http://dev-api.mysite.com/v1/',
loggingEnabled: true,
environmentName: 'Development'
};
Dynamic Solution
If you're looking for something a little more robust/dynamic you can use a plugin like replace-in-file, in conjunction with the environment files, best described in the accepted answer of How to insert a Build Number or Timestamp at build time in AngularCLI and Volodymyr Bilyachat's blog post Angular 2 - Manage application version which would allow something along the lines of:
export const environment = {
production: false,
version: '{BUILD_VERSION}',
apiUrl: 'http://dev-api.mysite.com/v1/',
loggingEnabled: true,
environmentName: 'Development'
}