How to change the environment configuration after the release of angular production environment?

how to change the environment configuration after the angular production environment is released?

for example, modify the webapi address of an angular connection.

because angular is compiled code, the api address cannot be modified directly.

how can I have a configuration file like java. Net to adjust configuration parameters for packaged code?

I know that angular has environment variables, but that is dead, and it is inconvenient to recompile every time you need to deploy the project to multiple client environments.

Mar.28,2021

how do you write URL now? Post some code


now environment.prod.ts

in the environment variable
export const environment = {
  production: true,
  api:"http://localhost/"
};

but this method is not convenient for the configuration adjustment of the production environment


I have the same problem. Have you solved the problem now? create a config file in


assets. The project introduces


the front-end code runs in the browser on the client side. Unlike the server-side code, the server-side generally configures an environment variable in the server operating system, and then the same code can select different config files according to the variables at run time. But the front-end code you cannot configure an environment variable on each client browser. So this determines that your packaged front-end code must be compiled according to environment variables.
different production environments generally use different environment files to make different configurations. Write script, for each environment in package.json and then deploy to different URL.
the convenient way is to configure CI/CD,pipeline and so on. Then it can be compiled, packaged and released automatically in one commit environment.

Menu