[英]what is the right way to import a node module to angular typescript / angularcli
im importing some "legacy" (non typescript) js libs to my angular SPA. 我将一些“传统”(非打字稿)js库导入我的角度SPA。
normally I just add a load from the cdn to index.html like: 通常我只是将CDN的负载添加到index.html中,例如:
<script src="//cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>
and in the angular-component i just decale 而在角度分量中,我只是降低了
declare var pako: any;
this typically works. 这通常有效。 Now i like to "host" this lib locally.
现在,我想在本地“托管”此库。 I can add it to the angular project with
我可以将其添加到角度项目
npm install pako
But how do I add it than to the angular app ? 但是,我如何将其添加到有角度的应用程序呢?
I tested adding an import to polyfills.ts (this works for hammerjs but not for pako) 我测试了将导入添加到polyfills.ts(这适用于Hammerjs但不适用于pako)
Also this should work for ng build (and than probably get added to the compiled / packed runtime.js 这也应该适用于ng build(并且可能会添加到已编译/打包的runtime.js中
BTW: here is a test stackblitz https://stackblitz.com/edit/ng-load-pako 顺便说一句:这是一个测试stackblitz https://stackblitz.com/edit/ng-load-pako
I love all the questions that provide a stackblitz link so that I can easily provide the correct answer: 我喜欢所有提供stackblitz链接的问题,因此我可以轻松提供正确的答案:
https://stackblitz.com/edit/ng-load-pako-gfunsb https://stackblitz.com/edit/ng-load-pako-gfunsb
Basically, you just need to do: 基本上,您只需要执行以下操作:
import * as pako from 'pako';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.