ng build --env=prod
一直在挑选environment.ts
而不是environment.prod.ts
这是一个错误吗?
我猜是因为 main.ts 默认导入environment.ts
import { environment } from './environments/environment';
main.ts
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/home/app.module';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
console.log(environment);
}
platformBrowserDynamic().bootstrapModule(AppModule);
environment.prod.ts
export const environment = {
production: true,
apiURL : '/offer-screener-web/'
};
environment.ts
export const environment = {
production: false,
apiURL : '/offer-screener-web/'
};
.angular-CLI
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"qa": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
ng -v
@angular/cli: 1.4.4
node: 8.5.0
os: darwin x64
@angular/cli: 1.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/compiler-cli: 4.3.6
typescript: 2.1.6
答案 0 :(得分:1)
您需要在所有环境的环境对象中设置envName
,类似这样的
export const environment = {
production: true,
apiURL : '/offer-screener-web/'
envName: 'prod'
};