Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 321
mhoff Avatar asked Oct 20 '25 17:10

mhoff


1 Answers

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

like image 143
Xinan Avatar answered Oct 22 '25 08:10

Xinan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!