Is there a way to pass arguments by CLI when building an Angular application?

Discussão em 'Angular' iniciado por guirms, Fevereiro 5, 2025.

  1. guirms

    guirms Guest

    I'm using Angular 16 and I have a specific scenario: My application will run locally in many machines, each one with one different ip, so that means that every server url will be different. Currently, I'm getting this url from the environment.ts, like this:

    export const environment = {
    apiUrl: 'http://11.22.33.44:5678/',
    };


    Currently, every time I need to build the application, I change the url manually. I want to do this by a CLI command. i.e ng build --configuration=production --serverUrl=http://55.66.77.88:5678/.

    This is my angular.json production section

    "configurations": {
    "production": {
    "fileReplacements": [
    {
    "replace": "src/environments/environment.development.ts",
    "with": "src/environments/environment.ts"
    }
    ]
    }


    I have read this question, but it says that I'll need to create one environment for each scenario. It's not fully dynamic.

    Continue reading...

Compartilhe esta Página