angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng serve does not support the "define" argument

Open Klaster1 opened this issue 1 year ago • 6 comments

Command

serve

Description

I want to pass environment variables into the application during serve and build. In Angular 19, this works for build: ng build --define="GGCC_TARGET='hosted'", while this doesn't for serve: ng serve --define="GGCC_TARGET='hosted'", with the following error:

Error: Unknown argument: define

Describe the solution you'd like

The --define argument works for both serve and build commands.

Describe alternatives you've considered

The custom "@ngx-env/builder:application" builder works, but I'd prefer to keep the amount of extra libraries to a minimum. Given how that builder is merely a thin wrapper around "@angular/build:application", I don't see why this couldn't work as I expect out of the box.

Klaster1 avatar Nov 20 '24 10:11 Klaster1

This behavior is expected since the define configuration is derived from the build section of the angular.json file when executing ng serve.

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
      "define": {
        "GGCC_TARGET": "'hosted'"
      },

alan-agius4 avatar Nov 20 '24 12:11 alan-agius4

Sorry, but I don't get it. Do you suggest to edit the "angular.json" instead of passing an env var, which worked for my team for years?

Klaster1 avatar Nov 20 '24 17:11 Klaster1

Does the value of GGCC_TARGET need to change between various ng serve invocations where its value is set via an environment variable?

alan-agius4 avatar Nov 20 '24 18:11 alan-agius4

Yes, I pass different values to run the app in different configurations, i.e with some fractures hidden and different brandings.

Klaster1 avatar Nov 20 '24 18:11 Klaster1

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Nov 22 '24 13:11 angular-robot[bot]

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] avatar Jan 01 '25 13:01 angular-robot[bot]