Babel ignore vs exclude option

Viewed 3346

I don't get the difference b/w babel exclude vs ignore option even after reading their documentation.

What I understood is that exclude is less aggressive than ignore. And exclude makes the current configuration object inactive and ignore stops the processing all together.

Maybe if someone from babel team(or any expert on babel can put up nicely for the general public out here would be much appreciated.

1 Answers

What I understood is that exclude is less aggressive than ignore. And exclude makes the current configuration object inactive and ignore stops the processing all together.

That's essentially accurate.

When a file is ignoreed, Babel will skip processing it entirely, which makes it good for excluding files that aren't JS, or files that you explicitly know should not be processed, like large already-bundled files.

The exclude key skips applying a given configuration block to a given file. This is primarily useful alongside the overrides option, allowing you to do things like this:

presets: ["@babel/preset-env"],
overrides: [
  {
    exclude: /node_modules/,
    plugins: ["babel-plugin-lodash"],
  },
],

for instance, if you wanted to compile all of your files with preset-env, but only process your local application files with babel-plugin-lodash.

Related