Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.min or src as "main"-file in package.json for node_module

I'm writing a Library for the Browser (JS, CSS) that was dependency-free up until now. Now I have at least one dependency and I'm thinking about wether or not to include the deps into the build or not.

Let's say my user uses a CDN - of course the minified file of my library should include the dependency. But what about module bundlers like webpack? If someone require/imports the lib, should the package.json point to the src entry or the minified file? Wouldn't the module bundler install and include the dependency anyway, so the minified file would be duplicate code (of the dependency)?

What's the best practice for this?

Namely, I build a leaflet plugin that will depend on some modules of turfJS. Leaflet is a peerDependency whereas turf is a dependency.

like image 448
ProblemsOfSumit Avatar asked Jul 31 '26 10:07

ProblemsOfSumit


1 Answers

jsDelivr let's you combine your dependencies. According to CDNperf, it offers one of the lowest latencies of any CDN.

.min or src as “main”-file in package.json for node_module

  • src: "main" field
  • min: "unpkg" field
like image 164
Knu Avatar answered Aug 01 '26 23:08

Knu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!