代码之家  ›  专栏  ›  技术社区  ›  Michael

正确的方法包装一个角度库,以支持角度8,9和10

  •  0
  • Michael  · 技术社区  · 5 年前

    随着Angular 10的发布,我正在将Angular用于构建库+演示应用程序的版本更新到版本10。

    通常情况下,这是顺利的,库仍然与Angular的早期版本兼容,但这似乎不是本版本的情况(以前的版本在Angular 9上构建可以与Angular 8兼容)。

    输出typescript定义文件包括:

    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'.
    

    我使用以下方法创建了test angular 8项目:

    npx @angular/cli@^8 new ngqrcode-ng8-test
    

    您可以在这里看到我的WIP请求: https://github.com/mnahkies/ng-qrcode/pull/8

    "angularCompilerOptions": {
        "enableIvy": false
      }
    

    有没有一种方法可以使用AngularV10构建一个库来保持与AngularV8的兼容性?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Abdessattar    5 年前

    1. 10需要tslib 2.0.0与<10需要tslib<2.0.0,
    2. 10使用typescript 3.9,而<10需要typescript<3.9

    我认为不能将8、9和10的lib打包在一个包中:-)