MithrilJS / mithril.js

A JavaScript Framework for Building Brilliant Applications
https://mithril.js.org
MIT License
14.01k stars 926 forks source link

re-add esm bundle, and switch extension to `module.js` instead of `mjs` #2420

Closed fuzetsu closed 2 months ago

fuzetsu commented 5 years ago

Description

In mithril 2.0.0-rc.5 the ESM bundle was removed (#2366). This was done mainly because of issues with webpack that caused confusion among users. Webpack would use the mjs file instead of the js file and not expose the default export in the standard way.

const m = require('mithril').default

preact had a similar issue because they also provided an mjs version of their bundle on npm. In their 10.0 beta they resolved this issue by changing the file extension to module.js which does not cause issues with webpack.

Why

Considering that most competing frameworks/libraries offer such a bundle, new users are likely to expect it, and even though using a script tag continues to work fine it's nice to have the option to use native modules when writing an app without a build process.

Other frameworks' bundle:

Possible Implementation & Open Questions

This is the commit that fixed the issue for preact. I propose we follow suit, and just change the extension to module.js.

https://github.com/preactjs/preact/commit/8ea29b5e92d69ddc4279833b19cb50294a91b923

Do we want to continue to use our custom scripts to generate the esm build? Are we ready for rollup or something similar? (maybe too much change at this point) #1886

Is this something you're interested in working on?

Yes

dead-claudia commented 5 years ago

Could you find some relevant discussion on Preact's side?

Also, I consider this a subbug of #1886, not a strict duplicate.

fuzetsu commented 5 years ago

@isiahmeadows

There doesn't seem to be a huge amount of discussion specifically about switching from mjs to js. but quite a bit around the issues pre switching. My impression is that getting rid of the module bundle was not an option for them, and changing the extension was an acceptable workaround, so they just went with it when they found it. There might be some behind the scenes discussion I'm not finding.

Here are few comments/isses that mention the switch: https://github.com/preactjs/preact/issues/1424#issuecomment-474527235 https://github.com/preactjs/preact/issues/1321 https://github.com/preactjs/preact/pull/1425 https://github.com/preactjs/preact-render-to-string/issues/86#issuecomment-485958898

I also checked their slack, but wasn't able to find many references to this topic there.

dead-claudia commented 5 years ago

Okay, it appears they've been pointing people to this Webpack plugin as a workaround, and we apparently weren't the only ones running into inconsistent module resolution logic with Webpack. (We may have just ran into a different variant of the same greater problem.)

I'm open to this, and feel free to send a PR. Here's generally what I'm thinking:

fuzetsu commented 5 years ago

Sound good! :+1: I'll try to submit a PR this week, hopefully tomorrow.

backspaces commented 5 years ago

Make sure to include a "module:" property in package.json so that unpkg, pika and other CDNs can serve the module easily.

dead-claudia commented 2 months ago

Closing due to age.