Skip to content

ng serve with multiple configurations #17696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kedevked opened this issue May 11, 2020 · 8 comments
Closed

ng serve with multiple configurations #17696

kedevked opened this issue May 11, 2020 · 8 comments
Assignees
Labels
area: @angular-devkit/build-angular area: docs Related to the documentation feature Issue that requests a new feature freq1: low Only reported by a handful of users who observe it rarely
Milestone

Comments

@kedevked
Copy link

🚀 Feature request

Following this PR it is now possible to extend build configuration.
Could it not possible to extends serve as well ? Additionnallly, ng serve always searches for entries under ng-serve. Could it not be possible that if those entries are not present it uses values directly under build ?

Description

if we suppose that we have 2 build environment and 3 localize entries, we will need 6 entries under serve to test it locally.

{
  "configurations": {
    "production": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.prod.ts"
        }
      ]
    },
    "production2": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.prod2.ts"
        }
      ]
    },
    "li18n1": {},
    "li18n2": {},
    "li18n3": {}
  }
}

If we are to use all these configs values under serve, we will need 6 entries. I wonder if it cannot be possible to run ng serve -c="i18n1, production1" and to directly use both configs

@alan-agius4 alan-agius4 added area: @angular-devkit/core feature Issue that requests a new feature labels May 12, 2020
@ngbot ngbot bot modified the milestone: Backlog May 12, 2020
@kyliau kyliau added triage #1 needs: discussion On the agenda for team meeting to determine next steps labels May 29, 2020
@SchnWalter
Copy link
Contributor

It seems to work for me. I've added extra build configurations and matching serve configurations, and then I tested both the serve command and the build command with multiple configurations, and they work just fine:

ng build -c production,uat-one
ng build -c production,uat-two
ng serve -c production,uat-one
ng serve -c production,uat-two

Here's the repository/branch in which I've tested this:

https://github.com/SchnWalter/repo-for-reproducing-angular-issues/tree/17696-ng-serve-with-multiple-configurations


P.S I've just noticed that you've used this command:

ng serve -c="i18n1, production1"

I think that you've been using the command wrong. The options are applied from right to left. So in your example, I think that you should use:

ng serve -c="production1, i18n1"

Here's a quote from the MR that you've linked:

They [configurations] will be applied from left to right. If --prod is also present, it will be considered to be the first configuration and thus able to be overriden.

@kedevked
Copy link
Author

kedevked commented Jun 4, 2020

Yes it is working. But we still need to redefine all the entries of configuration under serve. Maybe that ng serve -c "config" can default to the value of configuration when there is no config under serve

@dgp1130 dgp1130 added area: docs Related to the documentation and removed needs: discussion On the agenda for team meeting to determine next steps labels Jun 4, 2020
@SchnWalter
Copy link
Contributor

Those are just 3 lines per dev-server configuration entry, that's 18 extra lines for your 6 configurations, that's not much, you don't have hundreds of extra lines. Alternatively, you could use a script to generate a brand new angular.json from a template, and you could do this whenever you need to build for a certain brand or environment.

@kedevked
Copy link
Author

kedevked commented Jun 5, 2020

The point is valid. But if we can avoid writing a script because it can be provided out of the box, that will be better

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 19, 2020

@kedevked, that is not needed see #17473 (comment)

@alan-agius4 alan-agius4 added the freq1: low Only reported by a handful of users who observe it rarely label Jun 19, 2020
@kedevked
Copy link
Author

That's great, did not know about it. Thanks for sharing

@kyliau
Copy link
Contributor

kyliau commented Jun 19, 2020

To add on to @alan-agius4's reply, documentation for --browser-target is under works.
Meanwhile, @filipesilva wrote an excellent explanation of the flag in #16572 (comment).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular area: docs Related to the documentation feature Issue that requests a new feature freq1: low Only reported by a handful of users who observe it rarely
Projects
None yet
Development

No branches or pull requests

5 participants