我尝试使用 angular-cli 从 https://github.com/angular/angular-cli#build-targets-and-environment-files 配置环境设置
但是在我运行“ng build --prod -aot”之后,输出页面仍然显示原始环境/environment.ts 的内容。我希望这个文件会被 environment/environment.prod.ts 覆盖,但看起来不会。
我的文件夹结构是这样的:
- angular-cli.json
- ...
- src/
- app/
- ...
- environment/
- environment.dev.ts
- environment.prod.ts
- environment.ts
- main.ts
- ...
我的 angular-cli.json:
"apps": [
{
"root": "src",
...,
"environments": {
"dev": "environments/environment.dev.ts",
"prod": "environments/environment.prod.ts"
}
...
在我的 main.ts 文件中,我导入“环境”:
import { environment } from './environments/environment';
这是我的 ng 版本:
angular-cli: 1.0.0-beta.22-1 node: 6.9.1 os: win32 x64
有人知道我怎么了吗?真的很感谢。
最佳答案
在您的环境数组中添加源元素:
"source": "environments/environment.ts",
关于angular - 如何通过 angular-cli 配置 Angular 2 环境设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41254547/