I am trying to update my Angular 5.2 app to Angular 6. I successfully followed instructions in the Angular update guide (including the update of angular-cli
to v6), and now I am trying to serve the app via
ng serve --env=local
But this gives me error:
Unknown option: '–env'
I use multiple environments (dev/local/prod
), and this is the way it was working in Angular 5.2. How can I set the environment now in Angular 6?
Best Answer
You need to use the new
configuration
option (this works forng build
andng serve
as well)or
If you look at your
angular.json
file, you'll see that you have finer control over settings for each configuration (aot, optimizer, environment files,...)You can get more info here for managing environment specific configurations.
As pointed in the other response below, if you need to add a new 'environment', you need to add a new configuration to the build task and, depending on your needs, to the serve and test tasks as well.
Adding a new environment
Edit: To make it clear, file replacements must be specified in the
build
section. So if you want to useng serve
with a specificenvironment
file (say dev2), you first need to modify thebuild
section to add a new dev2 configurationThen modify your
serve
section to add a new configuration as well, pointing to the dev2build
configuration you just declaredThen you can use
ng serve -c dev2
, which will use the dev2 config file