angular - 打包 Angular 库以支持 Angular 8、9 和 10 的正确方法
问题描述
随着 Angular 10 的发布,我将用于构建库 + 演示应用程序的 Angular 版本更新到版本 10。
一般来说,这很顺利,并且该库仍然与以前版本的 Angular 兼容,但是这个版本似乎不是这种情况(针对 Angular 9 的先前版本构建与 Angular 8 配合得很好)。
输出打字稿定义文件包括:
import * as ɵngcc0 from '@angular/core';
...
static ɵfac: ɵngcc0.ɵɵFactoryDef<QrCodeComponent, never>;
static ɵcmp: ɵngcc0.ɵɵComponentDefWithMeta<QrCodeComponent, "qr-code", never, { "value": "value"; "size": "size"; "errorCorrectionLevel": "errorCorrectionLevel"; }, {}, never, never>;
在 Angular 8 项目中使用时会导致这样的错误:
ERROR in node_modules/ng-qrcode/lib/qr-code.component.d.ts(7,25): error TS2694: Namespace '"/ngqrcode-ng8-test/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDef'.
node_modules/ng-qrcode/lib/qr-code.component.d.ts(8,18): error TS2314: Generic type 'ɵɵComponentDefWithMeta' requires 6 type argument(s).
node_modules/ng-qrcode/lib/qr-code.directive.d.ts(13,25): error TS2694: Namespace '"/ngqrcode-ng8-test/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDef'.
我使用以下方法新创建了测试 angular 8 项目:
npx @angular/cli@^8 new ngqrcode-ng8-test
你可以在这里看到我的 WIP 拉取请求:https ://github.com/mnahkies/ng-qrcode/pull/8
注意:我的编译器选项中已经有 enableIvy false :
"angularCompilerOptions": {
"enableIvy": false
}
有没有办法使用 Angular v10 构建一个与 Angular v8 保持兼容性的库?
解决方案
角度 10 有 2 个重大的重大变化:
- 10 需要 tslib 2.0.0 与 <10 需要 tslib < 2.0.0,
- 10 使用 typescript 3.9 vs. < 10 需要 typescript < 3.9
我认为您不能将 8、9 和 10 的库打包在一个包中 :-)
推荐阅读
- php - Laravel - whereDoesntHave 在嵌套关系中
- javascript - 在javascript中构建多级数组后聚合数据
- ruby - 如何仅验证 json -schema 对象而不是其属性?
- c - 为什么在全局静态变量存在的情况下 BSS 不增加?
- android - 未通过邮件从 Facebook 接收标准应用程序事件代码
- c - 当 c 代码调用 fortran 子例程时,gcc 如何链接到 fortran IO 库。gcc 的典型错误是未定义符号“__gfortran_st_close”
- pandas - 如何过滤 DataDrame 并使用多个工作表生成多个 Excel 文件
- javascript - 如何从一个数字的字符串中减去 1
- apache-kafka - 为什么在 Flink SQL 客户端使用 Flink SQL Kafka 连接器会报错
- selenium - 如何使用 AndroidJUnit4 访问网页