-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(*): enable separate config for node_modules transpilation (#15270)
- Loading branch information
Showing
9 changed files
with
143 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file is heavily based on create-react-app's implementation | ||
// @see https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/dependencies.js | ||
|
||
const path = require(`path`) | ||
const resolve = m => require.resolve(m) | ||
|
||
module.exports = function(api, options = {}) { | ||
const absoluteRuntimePath = path.dirname( | ||
resolve(`@babel/runtime/package.json`) | ||
) | ||
|
||
return { | ||
// Babel assumes ES Modules, which isn't safe until CommonJS | ||
// dies. This changes the behavior to assume CommonJS unless | ||
// an `import` or `export` is present in the file. | ||
// https://github.com/webpack/webpack/issues/4039#issuecomment-419284940 | ||
sourceType: `unambiguous`, | ||
presets: [ | ||
[ | ||
// Latest stable ECMAScript features | ||
`@babel/preset-env`, | ||
{ | ||
// Allow importing core-js in entrypoint and use browserlist to select polyfills | ||
useBuiltIns: `usage`, | ||
corejs: 2, | ||
modules: false, | ||
// Exclude transforms that make all code slower (https://github.com/facebook/create-react-app/pull/5278) | ||
exclude: [`transform-typeof-symbol`], | ||
}, | ||
], | ||
], | ||
plugins: [ | ||
// Polyfills the runtime needed for async/await, generators, and friends | ||
// https://babeljs.io/docs/en/babel-plugin-transform-runtime | ||
[ | ||
resolve(`@babel/plugin-transform-runtime`), | ||
{ | ||
corejs: false, | ||
helpers: true, | ||
regenerator: true, | ||
// https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules | ||
// We should turn this on once the lowest version of Node LTS | ||
// supports ES Modules. | ||
useESModules: true, | ||
// Undocumented option that lets us encapsulate our runtime, ensuring | ||
// the correct version is used | ||
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42 | ||
absoluteRuntime: absoluteRuntimePath, | ||
}, | ||
], | ||
// Adds syntax support for import() | ||
resolve(`@babel/plugin-syntax-dynamic-import`), | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters