'Properly linking to a javascript library installed with npm?

When I install a JS library with npm, say:

npm install chartjs

It places the required JS file in ./node_modules/chartjs/chart.js.

Since I want the file to be located in, say, ./public/js/chart.js, I could just copy and paste it there. But is there a proper way to do that, like linking directly to the file installed by npm ?

Thanks in advance for your help. (Yes I'm kind of new to JS...)



Solution 1:[1]

In general, if you are using npm to manage your dependencies then you would use a bundler (such as Rollup, Webpack, or Parcel) to combine them into a browser-friendly file in your distribution directory.

MDN has a tutorial which walks through setting up a basic project in Parcel.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1