mjackson / unpkg

The CDN for everything on npm
https://unpkg.com
Other
3k stars 302 forks source link

Option to bundle and minify ES modules? #152

Open mbostock opened 5 years ago

mbostock commented 5 years ago

Related to autominification #57, I’d love it if ?module requests were automatically bundled (say using Rollup) as well as minified. This import currently triggers ~576 non-minified requests, which makes it somewhat unreasonable to recommend:

import("https://unpkg.com/d3?module")

I could ship bundled and minified ES modules for all the D3 modules using the module entry point, but that’s not ideal outside of unpkg because now source users (say people bundling D3 into their app) are also seeing pre-minified code. If unpkg supported multiple entry points #93, then I could specify a bundled and minified ES module for the unpkg-specific module entry point, but it’d be even more convenient if unpkg did this automatically.

My recommendation is that unpkg only bundle relative imports, and leave imports of bare module specifiers as (rewritten) imports, as ?module currently does. It should be possible to tell Rollup to externalize all such dependencies.

mjackson commented 5 years ago

I agree that it'd be nice to have a bundling feature for files in the same package, but I'm not sure the best way to go about it. There are 2 ways I can think of:

But ya, I've thought about this a lot too. 👍

WJCHumble commented 3 years ago

@mjackson is there any plan to support bundle ES Modules? Or is there another way? 😂

HugoGresse commented 2 years ago

Any news on this subject?
Having a bundled option to get a single file greatly improve performance, and in my use case it takes around 3.5s to get 60 .js files for a 90kb size :/