-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Unexpected Babel configuration behavior #36
Comments
Hi @d3dc Thanks for your feedback. Interesting, I haven't notice that. May I ask what side effects you are experiencing since craco updates both babel loaders? Do you see any use cases were someone would require to apply presets or plugins to both babel loaders? Thank you |
The second loader is intended to polyfill code for browsers I don't think there should be too many side-effects. The biggest is performance. Each plugin will traverse the AST for each import - and this happens for all of
Edit: I'm not sure why I confused the loaders... It really is setup to compile with all the plugins, except the
My use case is a little out of the ordinary - I'm trying to package my whole toolkit with a customized craco config and uncompiled library code. When using lerna's |
So to clarify, anything outside of
This does seem odd to automatically add all new plugins to. But as I mentioned, you may want to add your own polyfills. It is already pretty convenient to use a loaderOptions: opts => {
if (!opts.customize) {
// external files
return opts
}
return {
...opts,
...customization
}
} |
Hi @d3dc This is indeed an easy fix if you want to customize what's being configured for the files outside of the I might wait before updating any code for this one since I don't want to break anyone setup. How could craco's configuration be modified to accommodate your usecase? Maybe an {
babel: {
presets: [],
plugins: [],
loaderOptions: { }
applyToExternalFiles: true
}
} |
I ended up writing a custom function for my babel configuration. Its pretty close to the original, with two things:
overrideWebpackConfig({ webpackConfig, cracoConfig }) {
...
const {
externalLibs,
presets,
plugins,
loaderOptions,
} = cracoConfig.customBabel
matches.forEach(({ loader }) => {
if (loader.options.customize) {
Object.assign(loader.options, loaderOptions, {
presets: [...loader.options.presets, ...presets],
plugins: [...loader.options.plugins, ...plugins],
})
if (externalLibs) {
loader.include = (Array.isArray(loader.include)
? loader.include
: [loader.include]
).concat(externalLibs)
loader.exclude = {
test: loader.exclude || /node_modules/,
not: externalLibs,
}
}
}
})
return webpackConfig
} The boolean approach is probably better for react native libraries, as there could be frequent changes to the config with my way. I would think the performance would need testing before saying a whitelist is faster, but I also think a whitelist is faster. We both used the word "external" but I wonder if "applyOutsideSrc" is simpler. |
Thanks for sharing. I agree with you that |
Will be fix in #49 |
The babel config override will override the loaderOptions, presets, and plugins for both of the
babel-loader
rules CRA has.It seems like the second loader shouldn't receive the presets and plugins by default, since the second loader is meant for:
I would argue the behavior is unexpected since only files in
src/
are supposed to getbabel-preset-react-app
and previously tools such asreact-app-rewired
only modified the first loaderThe text was updated successfully, but these errors were encountered: