Skip to content

Allow to disable __esModule#2287

Merged
lukastaegert merged 1 commit into
masterfrom
allow-es-modules-disabling
Jun 20, 2018
Merged

Allow to disable __esModule#2287
lukastaegert merged 1 commit into
masterfrom
allow-es-modules-disabling

Conversation

@TrySound

Copy link
Copy Markdown
Member

Ref #708

This option will be useful for projects who distribute only cjs
and would like to migrate their codebase from default to named
exports but don't loose the ability to import in both ways.

For example react makes a hacky reexport right now

module.exports = React.default ? React.default : React;

Disabling __esModule will allow react to prepare their packages to esm.

Ref #708

This option will be useful for projects who distribute only cjs
and would like to migrate their codebase from default to named
exports but don't loose the ability to import in both ways.

For example react makes a hacky reexport right now

```js
module.exports = React.default ? React.default : React;
```

Disabling __esModule will allow react to prepare their packages to esm.
@guybedford

Copy link
Copy Markdown
Contributor

Just thinking through this here, if I made an entrypoint like:

react-entry.js

export { default } from './react.js';

Surely that would collapse down to the module.exports = React scenario, without an __esModule export? How does that not match the expected workflow in this case?

@TrySound

TrySound commented Jun 20, 2018

Copy link
Copy Markdown
Member Author

The case is that I want to migrate react from default exports to named exports without breaking changes. So there won't be default export in react esm but it will be achievable in cjs. This will allow to do more work before achieving esm support.
https://github.com/facebook/react/blob/master/packages/react/src/React.js

@guybedford

Copy link
Copy Markdown
Contributor

This sounds like a great effort, I'm just trying to understand why this isn't possible today. What if the entry above was written:

react-rollup-entry.js:

import * as React from './react.js';
export default React;

@guybedford

Copy link
Copy Markdown
Contributor

Or is the issue that you want to be able to run the "cjs" and "esm" build on the same rollup input options?

@TrySound

Copy link
Copy Markdown
Member Author

It's not achievable with reexport to default because of object.freeze which I can't disable because of react dependencies.

@guybedford

Copy link
Copy Markdown
Contributor

@TrySound I see, then it definitely makes sense to have a little more control. I can get behind this.

@lukastaegert

Copy link
Copy Markdown
Member

So between the lines I read that React will eventually be distributed as ESM as well? I remember a discussion that seemed to go nowhere at the end of last year. Great to hear you are moving forward here!

@TrySound

Copy link
Copy Markdown
Member Author

Yes, we need to be very carefully here to not break existing stuff. The plan is continue supporting both import * as React from 'react' and import React from 'react' in react17 and upgrading community stuff (code, docs, tutorials). After that there will be a chance to get rid from default export.

@lukastaegert lukastaegert merged commit d4aed73 into master Jun 20, 2018
@TrySound TrySound deleted the allow-es-modules-disabling branch June 20, 2018 15:27
@lukastaegert lukastaegert added this to the 0.61.0 milestone Jun 20, 2018
@lukastaegert

Copy link
Copy Markdown
Member

Will put this into an 0.61.0 release today, together with some other stuff.

@lukastaegert

Copy link
Copy Markdown
Member

You might have left a solo:true in the tests. Will need to fix some things before I can release.

@TrySound

Copy link
Copy Markdown
Member Author

Oops, sorry

@TrySound

Copy link
Copy Markdown
Member Author

I will make a PR

@lukastaegert

Copy link
Copy Markdown
Member

Nah, I already fixed everything

calebeby referenced this pull request in Pigmice2733/scouting-frontend Jun 21, 2018
This Pull Request updates dependency [rollup](https://github.com/rollup/rollup) from `v0.60.7` to `v0.61.1`



<details>
<summary>Release Notes</summary>

### [`v0.61.1`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0611)
[Compare Source](rollup/rollup@v0.61.0...697f36d)
*2018-06-21*
* Do not try to deconflict "undefined" ([#&#8203;2291](`https://github.com/rollup/rollup/pull/2291`))
* Properly track values for loop interator declarations and reassigned namespaces, add smoke test ([#&#8203;2292](`https://github.com/rollup/rollup/pull/2292`))

---

### [`v0.61.0`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0610)
[Compare Source](rollup/rollup@v0.60.7...v0.61.0)
*2018-06-20*
* Declare file dependencies via transform plugin hooks ([#&#8203;2259](`https://github.com/rollup/rollup/pull/2259`))
* Handle undefined values when evaluating conditionals ([#&#8203;2264](`https://github.com/rollup/rollup/pull/2264`))
* Handle known undefined properties when evaluating conditionals ([#&#8203;2265](`https://github.com/rollup/rollup/pull/2265`))
* Access watch events via the plugin context ([#&#8203;2261](`https://github.com/rollup/rollup/pull/2261`))
* Add option to suppress `__esModule` flag in output ([#&#8203;2287](`https://github.com/rollup/rollup/pull/2287`))
* Fix issue when re-declaring variables, track reassignments in more cases ([#&#8203;2279](`https://github.com/rollup/rollup/pull/2279`))
* Add VSCode debug settings ([#&#8203;2276](`https://github.com/rollup/rollup/pull/2276`))

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants