我创建了一个 Angular 11 库。在库工作区的 angular.json 文件中,我尝试添加 fileReplacements ,类似于普通 Angular 应用程序的操作方式。我在 angular.json 的配置部分中添加的代码如下所示。
"configurations": {
"production": {
"tsConfig": "projects/cw-component-lib/tsconfig.lib.prod.json",
"fileReplacements": [
{
"replace": "projects/cw-component-lib/src/lib/scss/theme.scss",
"with": "projects/cw-component-lib/src/lib/themes/themenew.scss"
}
]
}
}
cw-component-lib 是位于库的项目文件夹中的项目。现在,当我尝试运行构建命令 ng build cw-component-lib --prod 时,我收到以下错误
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(fileReplacements).
我不知道到底是什么导致了这个问题。请帮我解决这个问题。
最佳答案
TL;DR:不可能
Angular 库是使用不同的构建器构建的(@angular-devkit/build-angular:ng-packagr
而不是 @angular-devkit/build-angular:browser
)遗憾的是它不支持fileReplacements
。
查看有关同一件事的问题:https://github.com/angular/angular-cli/issues/12361
Hi, thanks for reporting this but the library builders doesn’t support any of those properties.
Valid properties are listed here: https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_ng_packagr/src/build/schema.json
(死链接)请参见此处:https://github.com/angular/angular-devkit-build-ng-packagr-builds/blob/master/src/build/schema.d.ts
/**
* ng-packagr target options for Build Architect. Use to build library projects.
*/
export interface Schema {
/**
* The file path for the ng-packagr configuration file, relative to the current workspace.
*/
project: string;
/**
* The full path for the TypeScript configuration file, relative to the current workspace.
*/
tsConfig?: string;
/**
* Run build when files change.
*/
watch?: boolean;
}
据我所知,没有(简单的)解决方法。我自己也在找。
关于angular - angular.json 中的文件替换导致 Angular 11 库中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65667660/