New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create .mjs entry points for module bundlers supporting ESM. #55
Conversation
In modern bundlers (ex: [Webpack][1] and [Rollup][2]), .mjs have a higher priority than .js. This change will make those load ES modules instead of the commonjs versions, so the code can be [treeshaked][3] and [hoisted][4]. This will bypass the Babel build, but in general bundlers will use a compiler to support the ES* features needed. [1]: https://webpack.js.org/configuration/resolve/#resolve-extensions [2]: https://github.com/rollup/rollup-plugin-node-resolve#usage [3]: https://webpack.js.org/guides/tree-shaking/ [4]: https://webpack.js.org/plugins/module-concatenation-plugin/
Thanks! I'll get this merged and published today. |
This change broke apollo-client for me. When upgrading I get |
Thanks for the report - reverting now. |
Reverted in feb8936 / 0.8.13. |
This is unfortunate, sorry for the regression. I wonder why a runtime error like this occurs when using .mjs files but not with the transpiled ones. I guess a major version bump would be needed for this change. |
@BenoitZugmeyer No problem! My hypothesis is that linking to untranspiled classes caused some transpiled "subclasses" to break. I don't think it had much to do with mjs. |
Sibling Here is how I go about it for my packages: https://unpkg.com/extract-files/ The package https://github.com/jaydenseric/extract-files/blob/v5.0.1/package.json#L58 The Babel config is identical for both, except a https://github.com/jaydenseric/extract-files/blob/v5.0.1/babel.config.js#L7 Note that source correctly has the https://github.com/jaydenseric/extract-files/blob/v5.0.1/package.json#L60 That way the ESM/CJS builds have seperate https://github.com/jaydenseric/eslint-config-env/blob/v2.0.0/index.js#L68 But I digress. I suggest using a
|
In modern bundlers (ex: Webpack and Rollup), .mjs have a higher priority than .js. This change will make those load ES modules instead of the commonjs versions, so the code can be treeshaked and hoisted.
This will bypass the Babel build, but in general bundlers will use a compiler to support the ES* features needed.