I would like to pass custom arguments to angular-cli
when building an Angular2
(typescript) app. Is this possible? How can I access this arguments in my code?
The scenario is like this: I have one Angular2
app with 2 layouts. Each layout has 3 colors (red, blue, green). I want to build all possible combinations. One app per layout and color => layout1red, layout1green, layout2blue, ...
I want to create 6 JSON config files for each build where I define the layout and color, and maybe some additional properties.
It is possible to create multiple configuration files with @angular/cli
.
As mentioned in docs custom configuration files can be add in the following way:
src/environments/environment.NAME.ts
{ "NAME": 'src/environments/environment.NAME.ts' }
to the apps[0].environments
object in .angular-cli.json
--env=NAME
flag on the build/serve commands.So, you would probably need 6 config files for dev and 6 config files for prod.
And then to access those variables just import environment object from environment.ts
file.