Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

use project-wide babel.config.js to compile node_modules #91

Closed
wants to merge 1 commit into from

Conversation

jingsam
Copy link

@jingsam jingsam commented Jun 21, 2019

this fix #89

@kepta
Copy link
Contributor

kepta commented Jun 22, 2019

I am afraid we would not be compiling Flow in node modules. We already compile newer Javascript versions in node_modules with the help of Babel, but configuring it is out of the scope of this project, though you can always configure it with the help of webpackConfigTransform

function getConfigForNodeModules(urc) {
const override = ({ name, options }) => {
if (name === '@babel/preset-react') {
return null;
}
if (name === '@babel/plugin-proposal-class-properties') {
return null;
}
if (name === '@babel/plugin-proposal-object-rest-spread') {
return null;
}
if (name === 'babel-plugin-transform-react-remove-prop-types') {
return null;
}
return options;
};
const loaderConfig = {
test: /\.js$/,
// We want to avoid sending babel/runtime back to babel.
exclude: /@babel(?:\/|\\{1,2})runtime/,
loader: require.resolve('babel-loader'),
options: {
presets: [
[
require('@mapbox/babel-preset-mapbox'),
{
// The override option allows for customizing each
// individual preset/plugin with the help of callback
// ref: https://github.com/mapbox/underreact/tree/next/packages/babel-preset-mapbox#advanced-configuration
override
}
]
],
// Ref: https://babeljs.io/docs/en/options#sourcetype
// By default Babel considers everything as an `EcmaScript Module`, which is not
// the case for most of the `node_modules`. This changes the behavior of
// Babel to assume CommonJS unless an `import` or `export` is present in the file.
sourceType: 'unambiguous',
babelrc: false,
configFile: false,
compact: false,
cacheDirectory: true,
cacheCompression: false,
sourceMaps: false,
cacheIdentifier: createCacheIdentifier({ urc })
}
};
// By default we compile all of the `node_modules`, but the user can also pass a
// selective list of node_modules to compile.
if (Array.isArray(urc.compileNodeModules)) {
loaderConfig.include = new RegExp(
urc.compileNodeModules.map(m => `${m}(?!/node_modules).*`).join('|')
);
}
return loaderConfig;
}

@kepta kepta closed this Jun 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flow error in node_modules
2 participants