gpt4 book ai didi

angular - 在 Angular CLI 中从 ng-build 中排除模块......不工作

转载 作者:太空狗 更新时间:2023-10-29 17:51:19 25 4
gpt4 key购买 nike

我有一个 Angular CLI 项目,里面有两个应用程序。这两个应用程序是相同的,但一个应用程序包含构建中的所有文件,另一个需要排除一个模块。

Angular CLI 版本:1.7.4 Angular 版本:5.2.10

我在 angular-cli.json 文件中添加了两个应用程序,每个应用程序都有一个单独的 ts-config 文件。

  "apps": [
{
"name": "app", <---- first app
"root": "src",
"outDir": "/wwwroot",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json", <----first TS config
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
},
{
"name": "admin", <---- second app
"root": "src",
"outDir": "/wwwroot",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.admin.json", <----- second ts config
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],

“管理”应用程序将包含所有文件。但是,应用程序数组中的第一个应用程序“app”将排除管理模块。

tsconfig.app.json:

{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts",
"app/modules/admin/" <----- note: I want this entire directory excluded from the build.
]
}

我在 package.json 文件中设置了两个“ng-build”脚本。

package.json 构建脚本:

"scripts": {
"build-app": "ng build -app app --prod",
"build-admin": "ng build -app admin --prod",
},

为了对此进行测试,我更改了管理模块中的一些文本和样式,并在本地运行构建。我注意到该应用程序的管理版本(应构建所有文件)有效,但该应用程序的“应用程序”版本并未排除管理模块。

有没有人看到上面的片段中遗漏/忽略了什么?有没有人遇到过类似的问题并找到了解决方案?

angular-cli 存储库关闭了这个问题,但没有提供修复。 see issue here

最佳答案

如果有人正在阅读本文并寻找答案:

TS 将构建它看到“导入”语句的任何文件,无论它是否在 tsconfig.json 的“排除”属性中。

我的 app.modules.ts 文件中有一个 import 语句,当我删除它时......它已成功从构建中排除。

关于angular - 在 Angular CLI 中从 ng-build 中排除模块......不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50334825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com