Salesforce does not provide support for third-party JavaScript libraries, but is possible to use external libraries with LWC.
Some restrictions apply:
<aside> ℹ️ Please review the official documentation on the minor details regarding Locker compliance and implications when using Javascript Strict Mode: Use Third-Party JavaScript Libraries | Lightning Web Components Developer Guide | Salesforce Developers
</aside>
This is a common procedure to use a 3rd party library:
import RESOURCE_NAME from "@salesforce/resourceUrl/RESOURCE_NAME"
platformResourceLoader
module: import {loadStyle, loadScript} from "lightning/platformResourceLoader"
loadStyle
and loadScript
to load the files from the static resource. These methods return promises.
Promise.all()
to aggregate the results and ensure that all required files from the library are resolved.then()
callback is invoked only after the load completes and only if no error occurs. You can optionally provide a catch()
callback to handle any potential error occurring during the load process.If you need to load more than 1 file from the static resource, use this mechanism:
Promise.all([
loadScript(this, RESOURCE_NAME + "/lib1.js"),
loadScript(this, RESOURCE_NAME + "/lib2.js"),
loadScript(this, RESOURCE_NAME + "/lib3.js"),
]).then(() => {
/* callback */
});