visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

Provide an es modules bundle #499

Closed lastmjs closed 5 years ago

lastmjs commented 5 years ago

Could you provide a rollup bundle that emits es modules? I'm working with tools (trying to work with no tools) that just assume es module source code. Bare specifiers are fine, but having the require syntax in the bundle is messing things up for me. It would be nice if page could have a module output, and for that to be in the "es" or "module" property of the package.json. I bring this up because I'm trying to use sk-router and ran into this issue: https://github.com/skatejs/skatejs/issues/1514

matthewp commented 5 years ago

That would be superb! Let me take a look at how difficult this would be and I'll get back to you.

lastmjs commented 5 years ago

Awesome! If it helps, I've done this kind of thing before on a few occasions:

And there are many others in the repo list: https://github.com/Prendus

matthewp commented 5 years ago

Yeah I've done it a bit before as well. This already uses rollup so I think it's just a matter of adding a second build target. I'll probably go with page.mjs since page.js is the UMD bundle.

Do you know what is supposed to be done about the package.json so that bundlers prefer this new bundle? Is that the module field?

lastmjs commented 5 years ago

I'm not sure, but I believe I've seen module and esm. module would probably be preferred: https://stackoverflow.com/questions/42708484/what-is-the-module-package-json-field-for

matthewp commented 5 years ago

https://github.com/visionmedia/page.js/pull/500

matthewp commented 5 years ago

This is in 1.9.0: https://github.com/visionmedia/page.js/releases/tag/v1.9.0