不推荐在“package.json”中配置 ng-packagr

Ram*_*bou 11 angular-cli ng-packagr

在构建带有子条目的 Angular 13 包时,我收到以下警告。

Building Angular Package
WARNING: Found configuration in ...<PATH_TO_PACKAGE>/package.json.
Configuring ng-packagr in "package.json" is deprecated. Use "ng-package.json" instead.
Run Code Online (Sandbox Code Playgroud)

所有相关信息均源自ng version

Angular CLI: 13.0.4
Node: 16.13.0
Package Manager: yarn 1.22.17
OS: linux x64

Angular: 13.0.3
... animations, cdk, common, compiler, compiler-cli, core
... elements, forms, language-service, material
... material-moment-adapter, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1300.3
@angular-devkit/build-angular   13.0.4
@angular-devkit/core            13.0.3
@angular-devkit/schematics      13.0.3
@angular/cli                    13.0.4
@schematics/angular             13.0.4
ng-packagr                      13.0.8
rxjs                            7.4.0
typescript                      4.4.4
Run Code Online (Sandbox Code Playgroud)

不知道这是否是误报或如何解决它,因为官方 ng-packagr 文档没有提到在 package.json 中使用 ng-packagr 已被弃用。

IMa*_*iak 12

你需要从中提取这个package.json

{
  "ngPackage": {
    "lib": {
      "entryFile": "public-api.ts",
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

到一个新文件ng-package.json

{
  "lib": {
    "entryFile": "public-api.ts"
  }
}
Run Code Online (Sandbox Code Playgroud)

检查了我的图书馆,对我有用!

  • 我不是在寻求解决方案。我从 ng-packagr 收到的警告消息中很好地解释了该解决方案。我要问的是为什么官方文档与弃用消息警告不一致。根据官方文档,他们建议该库的使用者在 package.json 中使用 ngPackage。 (3认同)