angular - 从角度环境中排除文件
问题描述
我正在构建一个安装在不同客户端中的应用程序。为此,我使用不同的环境,例如
环境.costumer1.ts 环境.costumer2.ts
事实是一些客户使用服务工作者,而另一个没有,所以我创建了两个不同的 app.module.ts
app.module.ts
app.module-without-service-worker.ts
因此,当客户要求我提供没有 Service Worker 的应用程序时(我使用了一个我不想显示谁不想要它的通知服务),我将它放在 angular.json 中的 fileReplacements
{
"replace": "src / app / app.module.ts",
"with": "src / app / app.module-without-service-worker.ts"
}
不好的是,在构建主应用程序时,我收到以下错误:
错误:在 D:/developments/Patient Portal/patient-portal-demo/pp demo front/src/app/app.component.ts 中键入 AppComponent 是 2 个模块声明的一部分:D:/development/Patient 中的 AppModule Portal/patient-portal-demo/pp demo front/src/app/app.module.ts和AppModule在D:/developments/Patient Portal/patient-portal-demo/pp demo front/src/app/app.module-没有-service-worker.ts!
有没有办法从环境中排除文件?
解决方案
在为自己寻找答案时,我找到了您的帖子。
我尝试了基于构建配置加载不同组件(和不同路由配置)的方法,它对我有用。
在 Angular 9 中工作。
这是我的 angular.json:
"build": {
...
"configurations": {
"custom": {
"fileReplacements": [
{
"replace": "projects/my-app/src/app/app.module.ts",
"with": "projects/my-app/src/app/app.module-custom.ts"
}
]
},
...
},
...
}
...
"serve": {
...
"configurations": {
...
"app": {
"browserTarget": "rest-generator-app:build:custom"
}
}
}
然后当我提供我的应用程序时:
ng serve my-app --port=3000 -o --configuration=custom
推荐阅读
- jquery - 单击多个帖子具有相同的div类和按钮类时获取img src
- html - 使用 Angular 7 按开始和结束匹配突出显示单词
- c++ - 截图和复制的位图部分在结构上有什么区别?
- windows - 批处理文件直到第二次运行才获得目录名称
- java - @Import 注册非@Component bean
- django - django 中的跨域会话共享
- c# - 在 .NET Standard 中为所有平台获取设备名称
- swift - 如何快速加载 LLVM 函数传递?
- azure-service-fabric - 是否可以在后端之间进行单个前端选择(动态定义)?
- c++ - c++ 二级依赖解析与运行路径