Is there a way to install a Javascript library usi...
# suitecommerce
v
Is there a way to install a Javascript library using npm install, and use it in a SC Extension? I've followed this document earlier for using a 3rd party library: https://developers.suitecommerce.com/add-a-third-party-javascript-library-to-an-extension But according to this document, I have to copy the files of the library in an extension's module and give it a name in its define method (if it is AMD compatible of course) and then I can use it. Is there a way to just install the library and use it directly? The issue is, the library I'm trying to use has a lot of files which reference each other, I'm trying to avoid to modify each of those files and set the define parameters on them manually.
p
Short answer: No. Long answer: SCA's is not NPM aware for Extensions. I'd recommend you just look for a "build" version that is 1 file only - this is quite common to see. If the js is for frontend, and it's only for one specific page you can also just load that file with jQuery.getScript for your current view and add the js library as just an asset.
👍 2
s
Just to add, using something like getScript() is generally OK. AMD is better for a number of reasons including the fact that it removes an HTTP request
👍 1
p
Indeed. getScript would be on the case of a big library, and only if it's used only for one page. This would avoid making js files bigger on page load (which are already terribly huge at > 1 MB each for core + another file for your extensions). Which is something that google page speed complains a LOT about SCA in mobile.
s
That's a good way of looking at it
v
That is helpful information @PabloZ @Steve Goldberg Thank you. 🙂