Peter Penzov
Peter Penzov

Reputation: 1648

Run ng build with custom configurations

I have Angular project which I would like to deploy on Apache server. I use ng build but I would like to custom address and endpoint for backend.

proxy.conf.json:

{
  "/api/*": {
    "target": "http://localhost:8080",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

This configuration is not applied at all. How I can set it properly in order to change configurations?

Environment ts file:

import {environment as prod} from './environment.prod';

export const environment = Object.assign(prod, {
  production: false
});

Upvotes: 7

Views: 39122

Answers (2)

veben
veben

Reputation: 22262

You can define different environment files. Below example for "dev":

export const environment = {
    production: false,
    envName: 'dev',
    configPath: './assets/config/config.dev.json'
    ...
};

Add a configuration part for "dev" in "angular.json" file, like that:

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

And use this command to build : ng build --configuration=dev

For more information, take a look at this post : How to set environment via `ng serve` in Angular 6

Upvotes: 12

Pardeep Jain
Pardeep Jain

Reputation: 86720

Assuming you are using Angular (>v6), and you have created multiple environment files as per requirements.

So what you need to do is, go to angular.json file

angular.json > projects > projectName > architect > build > configurations > fileReplacements

and here you need to replace files name with your files name like this -

"replace": "src/environments/environment.ts",
"with": "src/environments/environment.live.ts"

Upvotes: 2

Related Questions