0

I've found a very useful node module that has dependencies. If I install it, it installs a total of five modules. Is there an easy way to make use of this module in Lightning Web Components?

1 Answer 1

2

Yes. To do so, install browserify or tinyify, and run the appropriate commands against the main module. The output will be a file suitable for including into a web browser. From there, simply follow the directions in Use Third-Party JavaScript Libraries. Note, there are particular limits regarding some maximum file sizes, such as the maximum file size of a Static Resource. It is recommended that you use some kind of minification (e.g. tinyify) if the libraries are quite large.

In contrast, if the total size falls under 128kb (131,072 characters), you can also just create a service component, as I outline in this answer. Or, of each module fits inside those size limits, you can convert each module into an ES6 friendly format by including an export command at the end of each. This would only take a couple of minutes.

Finally, it needs to be said, that many types of modules may not be compatible at all. It depends on what the module does, and what the dependencies do. Not all npm modules are compatible with LWC, or perhaps even the Internet in general, since they may use concepts that are not included in browsers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .