使用外部 js 库构建 Angular 5 个包

Build Angular 5 package with external js librairies

我已经为 JS 库创建了一个包装器,我想通过 npm 分享它。

因此,为此,我使用 SystemJS 和脚本加载器来加载 js 库。 它工作正常,我可以在生产模式下构建我的解决方案。

但是如果我尝试使用 angular-package-builder 创建一个 Angular 包,我得到了这个错误:

   [TypeScript] ngx-pivot-table/ngx-pivot-table.component.ts(22,5): error TS2304: Cannot find name 'System'.
   [TypeScript] ngx-pivot-table/ngx-pivot-table.component.ts(23,7): error TS2304: Cannot find name 'System'.
   [TypeScript] ngx-pivot-table/ngx-pivot-table.component.ts(25,7): error TS2304: Cannot find name 'System'.

这是我的组件代码:

  ngOnInit(): void {
    System.import('script-loader!./pivot.min.js').then(() => {
      this.render();
    }); 
  }

这是我的 typing.d.ts 文件:

/* SystemJS module definition */
declare var System: SystemJS;

interface SystemJS {
  import: (path?: string) => Promise<any>;
}enter code here

declare var module: NodeModule;
interface NodeModule {
  id: string;
}

将 typings.d.ts 的内容移动到组件代码的顶部。