Use package.json#imports for browser-specific code#17756
Use package.json#imports for browser-specific code#17756nicolo-ribaudo merged 4 commits intobabel:mainfrom
package.json#imports for browser-specific code#17756Conversation
e0c8c4d to
c9c7b90
Compare
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60807 |
3b9b1b9 to
ea4c555
Compare
|
commit: |
e34fc7e to
963e15e
Compare
| "default": "./lib/transform-file.js" | ||
| }, | ||
| "#hack-for-rollup-inlining-order-1": "./lib/errors/rewrite-stack-trace.js", | ||
| "#hack-for-rollup-inlining-order-2": "./lib/config/caching.js" |
There was a problem hiding this comment.
This is Rollup to force to create two separate files for these, otherwise it bundles them in an order that causes TDZ errors.
36fd0db to
08d7b1a
Compare
08d7b1a to
d1a76a3
Compare
| "./src/config/files/index.ts": "./src/config/files/index-browser.ts", | ||
| "./src/config/resolve-targets.ts": "./src/config/resolve-targets-browser.ts", | ||
| "./src/transform-file.ts": "./src/transform-file-browser.ts" | ||
| }, |
There was a problem hiding this comment.
This is a breaking change for downstream tools/frameworks that bundle babel-core or the transform-runtime package, if they still uses legacy webpack / rollup versions that does not recognize the imports field.
There was a problem hiding this comment.
Yes, however package.json#imports have been introduced in 2019. Webpack and Rollup have both supported it since 2020 (webpack/enhanced-resolve@effa185, rollup/plugins@0e4f014).
I think it is reasonable to expect for people that are updating to Babel 8 and want to bundle it to use a bundler released in the past 6 years. It's very likely that at this point we are shipping syntax that is not compatible with those bundlers too.
There was a problem hiding this comment.
It's very likely that at this point we are shipping syntax that is not compatible with those bundlers too.
You are right. To clarify, I don't object the change itself, but would rather point out that since it will break old bundlers anyway, at least we should mention this change in the migration note.
|
I like this PR! |
Fixes #1, Fixes #2Rather than our custom setup. This PR now also allows bundling packages with multiple entrypoints, or packages that have browser overrides. For example, for
@babel/core, it generates: