*`cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is set to `true` in options (`{cacheDirectory: true}`), the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules`foldercouldbefoundinanyrootdirectory.
*`cacheIdentifier`: Default is a string composed by the `@babel/core`'s version, the `babel-loader`'s version, the contents of `.babelrc` file if it exists, and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV`environmentvariable.Thiscanbesettoacustomvaluetoforcecachebustingiftheidentifierchanges.
*`cacheCompression`: Default `true`. When set, each Babel transform output will be compressed with Gzip. If you want to opt-out of cache compression, set it to `false`--yourprojectmaybenefitfromthisifittranspilesthousandsoffiles.
*`customize`: Default `null`. The path of a module that exports a `custom` callback [like the one that you'd pass to `.custom()`](#customized-loader). Since you already have to make a new file to use this, it is recommended that you instead use `.custom` to create a wrapper loader. Only use this if you _must_ continue using `babel-loader`directly,butstillwanttocustomize.
##Troubleshooting
###babel-loaderisslow!
Makesureyouaretransformingasfewfilesaspossible.Becauseyouareprobablymatching`/\.m?js$/`, you might be transforming the `node_modules`folderorotherunwantedsource.
Toexclude`node_modules`, see the `exclude` option in the `loaders`configasdocumentedabove.
Forthis,youcaneitheruseacombinationof`test` and `not`, or [pass a function](https://webpack.js.org/configuration/module/#condition) to your `exclude`option.Youcanalsousenegativelookaheadregexassuggested[here](https://github.com/webpack/webpack/issues/2031#issuecomment-294706065).
```javascript
{
test:/\.m?js$/,
exclude:{
test:/node_modules/,// Exclude libraries in node_modules ...
not:[
// Except for a few of them that needs to be transpiled because they use modern syntax
Seethe[docs](https://babeljs.io/docs/plugins/transform-runtime/) for more information.
**NOTE**:Youmustrun`npm install -D @babel/plugin-transform-runtime` to include this in your project and `@babel/runtime` itself as a dependency with `npm install @babel/runtime`.
Since[@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-runtime) includes a polyfill that includes a custom [regenerator-runtime](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/runtime.js) and [core-js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:
`core-js` and `webpack/buildin`willcauseerrorsiftheyaretranspiledbyBabel.
Youwillneedtoexcludethemform`babel-loader`.
```js
{
"loader":"babel-loader",
"options":{
"exclude":[
// \\ for Windows, / for macOS and Linux
/node_modules[\\/]core-js/,
/node_modules[\\/]webpack[\\/]buildin/,
],
"presets":[
"@babel/preset-env"
]
}
}
```
##Customizeconfigbasedonwebpacktarget
Webpacksupportsbundlingmultiple[targets](https://webpack.js.org/concepts/targets/). For cases where you may want different Babel configurations for each target (like `web` _and_ `node`), this loader provides a `target` property via Babel's [caller](https://babeljs.io/docs/en/config-files#apicallercb) API.