angular - angular.json 中的文件替换导致 Angular 11 库中出现错误

标签 angular configuration angular-library

我创建了一个 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/

相关文章:

angular - 在 Angular 2中,没有检测到 `bs-config.json`或 `bs-config.js`覆盖文件。使用精简服务器默认值?

configuration - AWS IAM用户策略以限制对特定SQS队列的访问

angular - 如何在没有 NPM 的情况下共享 Angular 库

angular - 将第三方库导入 Angular 库会报错

javascript - 动态地将一个组件追加到另一组件中

angular - 当一个 Action 被调度时做一些事情

javascript - 在 Angular 7 中使用 PathLocationStrategy 后刷新页面时获取 404

configuration - 如何使用 Clozure Common Lisp 创建应用程序(在 Microsoft Windows 上)

symfony - 如何在services.yml中引用parameters.yml?

使用 forRoot 的 Angular 库