Using Third-Party JavaScript Libraries in Lightning Web Components
At times we might have to make use of a third party library and use it in LWC. There is no way we can use a CDN and include it in <script></script>
tags in a Lightning Web Component.
So the route that we are gonna take it is using static resources in Lightning Web Component.
Create or download the library file and push it to static resources. From the static resources using the standard out of the box named imports to fetch a reference to Static Resource and use it in the controller.js file.
This is how the controller.js
file is going to look like.
Create a JavaScript file like this and upload it to static resources. The name of the JS file is going to be calculatePrincipleInterest.js
This is how the static resource is going to look like.
Using static resources in Lightning Web Component is going to be very handy as we can provide a very high level of abstraction and have only the necessary code in the Lightning Web Components.