Import and use a Node Package

441
2
05-04-2021 09:49 AM
WilsonIonara
New Contributor III

I am working on a typescript project with the 4.17 library. The template was downloaded from the github link below. I am having a hard time figuring out how to import a node library (I am trying to import pdf-merger-js after installing it with the npm install command). I know I can use a CDN link or have the js file referenced in my index.js but this library doesn't offer neither, and I really would like to learn how to use Node packages in this kind of project. Any help would be greatly appreciated. Thanks

https://github.com/Esri/jsapi-resources/tree/master/4.x/typescript

 

Tags (2)
0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor

If you want to use node packages, you'll need to use some sort of build tooling. That demo just compiles the TS to JS, but does no bundling of any sort. Tools like rollup and webpack can do that for you.

https://github.com/Esri/jsapi-resources/tree/master/esm-samples

https://github.com/Esri/jsapi-resources/tree/master/4.x/webpack/demo

If you are just getting started, the cli might be useful to try.

https://github.com/Esri/arcgis-js-cli

 

0 Kudos
WilsonIonara
New Contributor III

Thank you! I decided to use Webpack

0 Kudos