0

In Angular 15, There is no environment files so we are using proxy.config file for setting api path for local development but that will not work in production build.

Below is the proxy.config.json file. enter image description here

This is my package.json file. enter image description here

is anyone has suggestion for production build work with dynamic api path setting?

Bhadresh Patel
  • 1,671
  • 17
  • 18
  • the way to do this is with evironment.ts files. Add them to your build process. –  Jan 05 '23 at 12:56
  • From Angular 15, Environment files are removed. So we have to manage without environment file. – Bhadresh Patel Jan 05 '23 at 13:17
  • Does this answer your question? [Angular 15 CLI does not create environments folder when creating an angular project via ng new](https://stackoverflow.com/questions/74558182/angular-15-cli-does-not-create-environments-folder-when-creating-an-angular-proj) – Andrew Allen Jan 05 '23 at 13:18
  • Environment files were removed but this does not mean you cannot use environment files – Andrew Allen Jan 05 '23 at 13:20
  • is there any other option without adding Environment files? – Bhadresh Patel Jan 09 '23 at 16:02

2 Answers2

1

Environment files have been removed for convenience purposes : when a new user comes to the framework, this is less boilerplate code to deal with.

The same applies to karma conf, test config, etc.

That does not mean you can't add them back.

But just in case, a new feature is this one :

import { isDevMode } from '@angular/core';

This states if you're in dev mode or prod mode. You can work with that if all you need is a different URL.

MGX
  • 2,534
  • 2
  • 14
-1

you can set the API path for your production build by using the --base-href flag when you run the

ng build

command. This flag specifies the base URL that will be used for the application, and it will be prepended to all the URLs used in the application. You can also set the baseHref property in the angular.json file under the build options for your project. For example:

"build": {
  "options": {
    "baseHref": "https://api.example.com"
  }
}
  • This is NOT for the API. It also applies to every file served by the http server. – MGX Jan 05 '23 at 15:15