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

508 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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