问题
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
});
回答1:
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"
回答2:
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 user this command to build : ng build --configuration=dev
Take a look at this post : How to set environment via `ng serve` in angular 6
来源:https://stackoverflow.com/questions/53411274/run-ng-build-with-custom-configurations