babel-loader
babel-loader copied to clipboard
include / exclude not behaving as expected
I'm submitting a bug report
Webpack Version: 4.28.3
Babel Core Version: 7.2.2
Babel Loader Version: 8.0.5
Please tell us about your environment: OSX 10.x
Current behavior:
Does not parse files I've both explicitly included and explicitly not excluded. Demo of bug here:
https://github.com/apolitical/babel-include-exclude-bug
Built file correctly transforms out arrow function but not query-string
Expected/desired behavior:
exclude: () => false
means not excluded
include: () => true
means included
We solved it, Babel 7 treats .babelrc differently. This actually seems to be a documentation / communication problem I think.
I've always used .babelrc, however this now only works at the project level and does not delve into node_modules. Binning .babelrc and just putting the babel config inside webpack worked correctly.
The change is somewhat hidden in the babel documentation (or at least all of our devs missed it) and it's not mentioned in the babel-loader documentation at all.
What would be the best way to make sure this is clear to people?
what is the best config for include/exclude?
to exclude all node_modules in a monorepo?
If you want to exclude all the node_modules
, this should be enough:
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]