-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Add ESM artifacts to build outputs #17453
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 87594d7:
|
Details of bundled changes.Comparing: 6470e0f...87594d7 react
react-dom
react-flight-dom-webpack
react-noop-renderer
react-is
react-interactions
react-art
scheduler
react-native-renderer
create-subscription
react-refresh
react-reconciler
react-test-renderer
react-cache
jest-react
eslint-plugin-react-hooks
react-debug-tools
react-flight
react-server
use-subscription
ReactDOM: size: 🔺+0.2%, gzip: 🔺+0.6% React: size: -0.7%, gzip: -0.5% Size changes (experimental) |
Details of bundled changes.Comparing: 6470e0f...87594d7 react
react-dom
react-flight-dom-webpack
react-art
react-native-renderer
react-noop-renderer
react-cache
react-interactions
react-flight
react-test-renderer
scheduler
jest-react
create-subscription
react-is
react-refresh
react-server
react-reconciler
eslint-plugin-react-hooks
react-debug-tools
use-subscription
ReactDOM: size: -0.1%, gzip: -0.1% React: size: -1.0%, gzip: -0.6% Size changes (stable) |
…production bundle for now The amp-project closure compiler plugin was not doing much
I'm not done with my PR. I still wait til #15037 will be landed. Finishing my solution is waisting of your time. It does not solve issues with treeshaking. |
…ges using --experimenta-conditional-exports feature
@TrySound I'm not sure I'd agree that it was a waste - at the very least I think I got something out of it - but whether the React team wants a solution that uses experimental node features is an unknown. If they are, I think pushing the needle forward on this is totally achievable. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
Overview
Continuation on #13321. This PR adds ESM outputs to most libraries - excluding reconciler, devtools, and react-native libraries. There's still some more work to be done WRT verifying the ESM output, but I think it's at a point where it's ready for comments to see if it's worth pursuing further.
TODO
react-is
is published with esm support, which is part of this PR..--experimental-conditional-exports
flag)module
fields to packagesArtifacts
Bundles may be configured with the additional build targets
ESM_DEV
andESM_PROD
. The build output will generate the following files:Module Entry
Packages that support ESM are structured using the Dual CommonJS/ESModules Pattern using the conditional exports feature.
Packages may define an
__exports
field to support ESM. This is prefixed with a double-underscore to avoid file resolution issues with build. (e.g. import <package/src/x> will break if exports is set during build). During build each package's __exports field is assigned into theexports
field of the final build.Packages may also define top-level
.mjs
files in thenpm/
folders, similar to how they currently include top-levelindex.js
files. These can be used to define the modular API.Verification
Module structure is verified with a new script: test-package-structure, which is performed after the packages are built. This script depends on NodeJS >= 13.2 with the
--experimantal-conditional-exports
flag. The goal of this script is to ensure that packages are aligned with future NodeJS specifications for ES Modules. This script verifies the following invariants over each built package:main
field is present in package.json, the file it references exists.exports
specification exists in package.json, the files it references exist.files
for each package.json exist.require
statementexports
can be included withrequire()
andimport()
Sample Output:
sample package validator output: