babel-loader icon indicating copy to clipboard operation
babel-loader copied to clipboard

include / exclude not behaving as expected

Open Gisleburt opened this issue 5 years ago • 3 comments

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

Gisleburt avatar Jan 21 '19 11:01 Gisleburt

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?

Gisleburt avatar Jan 21 '19 13:01 Gisleburt

what is the best config for include/exclude?

to exclude all node_modules in a monorepo?

sibelius avatar Mar 18 '20 13:03 sibelius

If you want to exclude all the node_modules, this should be enough:

rules: [
  {
    test: /\.js$/,
    exclude: /node_modules/,
    loader: "babel-loader"
  }
]

nicolo-ribaudo avatar Mar 18 '20 14:03 nicolo-ribaudo