简体   繁体   中英

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.

normally I just add a load from the cdn to index.html like:

<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)

Also this should work for ng build (and than probably get added to the compiled / packed runtime.js

BTW: here is a test 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:

https://stackblitz.com/edit/ng-load-pako-gfunsb

Basically, you just need to do:

import * as pako from 'pako';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM