Skip to content
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

Consider supporting `__esModule` flag on CommonJS #496

Closed
guybedford opened this issue Feb 5, 2016 · 5 comments

Comments

Projects
None yet
6 participants
@guybedford
Copy link
Contributor

commented Feb 5, 2016

CommonJS modules that have the defineProperty(exports, '__esModule', { value: true }) thing could potentially be inferred as ES modules automatically in Rollup, and their exports bindings treated as such. Almost a sort of reverse CommonJS -> ES6 transformation. This would allow any modules transpiled with Babel into CommonJS to support Rollup optimizations due to their bindings nature.

This would greatly improve Rollup's ability to inline modules, as a sort of alternative to the jsnext:main thing.

Just sending the idea along though, feel free to close.

@Victorystick

This comment has been minimized.

Copy link
Member

commented Feb 5, 2016

It's a good idea, for sure. More npm modules are available as CommonJS processed by Babel than are proper ES modules. See rollup/rollup-plugin-commonjs#10, rollup/rollup-plugin-commonjs#16 and rollup/rollup-plugin-commonjs#29 for some Babel/CommonJS related issues.

This issue, if handled, should probably be done by the CommonJS plugin. Or an un-babel plugin, that assumes it's working with code that used to be proper ES modules.

@bfred-it

This comment has been minimized.

Copy link
Member

commented Mar 19, 2016

Not only supporting, but also exporting it. My CJS rollup exports are not being recognized correctly by babel because its version of _interopDefault only checks for the __esModule property.

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

Source: https://github.com/babel/babel/blob/5b89849f432cfc034860f495b5001039123e7754/packages/babel-helpers/src/helpers.js#L238-L242

@Nathan-Wall

This comment has been minimized.

Copy link

commented Jun 13, 2016

I'm trying to set up a system where I can write code using ES2015 modules, transform to AMD for development, and Rollup to a bundle for deployment. Having Rollup, Babel, and RequireJS understand each others output better would be helpful for me. I think this would be a good step.

@eventualbuddha

This comment has been minimized.

Copy link
Member

commented Jun 13, 2016

Rollup does now output this flag. Whether the CommonJS plugin handles it specially I don't know.

@Rich-Harris

This comment has been minimized.

Copy link
Contributor

commented Dec 22, 2016

Will close this as recent versions of rollup-plugin-commonjs handle transpiled modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.