{"id":13451795,"url":"https://github.com/babel/babel-loader","last_synced_at":"2026-03-06T12:07:38.588Z","repository":{"id":21643107,"uuid":"24963784","full_name":"babel/babel-loader","owner":"babel","description":"📦 Babel loader for webpack","archived":false,"fork":false,"pushed_at":"2026-02-28T03:42:30.000Z","size":5616,"stargazers_count":4849,"open_issues_count":64,"forks_count":451,"subscribers_count":71,"default_branch":"main","last_synced_at":"2026-03-02T07:11:15.921Z","etag":null,"topics":["babel","loader","webpack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/babel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["babel"],"open_collective":"babel"}},"created_at":"2014-10-08T22:30:13.000Z","updated_at":"2026-02-25T23:31:02.000Z","dependencies_parsed_at":"2025-12-14T07:00:50.936Z","dependency_job_id":null,"html_url":"https://github.com/babel/babel-loader","commit_stats":{"total_commits":501,"total_committers":127,"mean_commits":"3.9448818897637796","dds":0.8582834331337326,"last_synced_commit":"f765949ecec8ba7bfdc06c0447bc92d8e0f34422"},"previous_names":["couto/6to5-loader"],"tags_count":80,"template":false,"template_full_name":null,"purl":"pkg:github/babel/babel-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabel-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabel-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabel-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabel-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babel","download_url":"https://codeload.github.com/babel/babel-loader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabel-loader/sbom","scorecard":{"id":33508,"data":{"date":"2025-08-11","repo":{"name":"github.com/babel/babel-loader","commit":"2479ed223262f9ce45f9f7a9b8363a8666d9b41f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":6.3,"checks":[{"name":"Maintained","score":1,"reason":"2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":8,"reason":"Found 21/26 approved changesets -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/ci.yml:6","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/babel/babel-loader/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/babel/babel-loader/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/babel/babel-loader/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/babel/babel-loader/ci.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/babel/babel-loader/ci.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 27 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-14T19:44:22.759Z","repository_id":21643107,"created_at":"2025-08-14T19:44:22.759Z","updated_at":"2025-08-14T19:44:22.759Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30009513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T15:15:59.058Z","status":"ssl_error","status_checked_at":"2026-03-02T15:15:58.758Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel","loader","webpack"],"created_at":"2024-07-31T07:01:02.797Z","updated_at":"2026-03-06T12:07:38.580Z","avatar_url":"https://github.com/babel.png","language":"JavaScript","readme":"\u003e This README is for babel-loader v8/v9/v10 with Babel v7\n\u003e If you are using legacy Babel v6, see the [7.x branch](https://github.com/babel/babel-loader/tree/7.x) docs\n\n[![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader)\n[![codecov](https://codecov.io/gh/babel/babel-loader/branch/main/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader)\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/babel/babel\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/babel/logo/master/babel.svg\" alt=\"Babel logo\" width=\"200\" height=\"200\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg src=\"https://webpack.js.org/assets/icon-square-big.svg\" alt=\"webpack logo\" width=\"200\" height=\"200\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003ch1 align=\"center\"\u003eBabel Loader\u003c/h1\u003e\n\nThis package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) together with [webpack](https://github.com/webpack/webpack) or [Rspack](https://github.com/web-infra-dev/rspack).\n\n**Note**: Issues with the output should be reported on the Babel [Issues](https://github.com/babel/babel/issues) tracker.\n\n\u003ch2 align=\"center\"\u003eInstall\u003c/h2\u003e\n\n\u003e | babel-loader | supported webpack versions | supported Babel versions | supported Node.js versions |\n\u003e |:-:|:-:|:-:|:-:|\n\u003e | 8.x | 4.x or 5.x | 7.x | \u003e= 8.9 |\n\u003e | 9.x | 5.x | ^7.12.0 | \u003e= 14.15.0 |\n\u003e | 10.x | ^5.61.0 | ^7.12.0 \\|\\| ^8.0.0-alpha | ^18.20.0 \\|\\| ^20.10.0 \\|\\| \u003e=22.0.0` |\n\n\n```bash\nnpm install -D babel-loader @babel/core @babel/preset-env webpack\n```\n\n\u003ch2 align=\"center\"\u003eUsage\u003c/h2\u003e\n\nwebpack documentation: [Loaders](https://webpack.js.org/loaders/)\n\nWithin your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:\n\n```javascript\nmodule: {\n  rules: [\n    {\n      test: /\\.(?:js|mjs|cjs)$/,\n      exclude: /node_modules/,\n      use: {\n        loader: 'babel-loader',\n        options: {\n          targets: \"defaults\",\n          presets: [\n            ['@babel/preset-env']\n          ]\n        }\n      }\n    }\n  ]\n}\n```\n\n### Options\n\nSee the `babel` [options](https://babeljs.io/docs/en/options).\n\nYou can pass options to the loader by using the [`options`](https://webpack.js.org/configuration/module/#ruleoptions--rulequery) property:\n\n```javascript\nmodule: {\n  rules: [\n    {\n      test: /\\.(?:js|mjs|cjs)$/,\n      exclude: /node_modules/,\n      use: {\n        loader: 'babel-loader',\n        options: {\n          targets: \"defaults\",\n          presets: [\n            ['@babel/preset-env']\n          ],\n          plugins: ['@babel/plugin-proposal-decorators', { version: \"2023-11\" }]\n        }\n      }\n    }\n  ]\n}\n```\n\nThe `options` passed here will be [merged](https://babeljs.io/docs/configuration#how-babel-merges-config-items) with Babel config files, e.g. `babel.config.js` or `.babelrc`.\n\nThis loader also supports the following loader-specific option:\n\n* `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` folder could be found in any root directory.\n\n* `cacheIdentifier`: Default is a string composed by the `@babel/core`'s version and the `babel-loader`'s version. The final cache id will be determined by the input file path, the [merged](https://babeljs.io/docs/configuration#how-babel-merges-config-items) Babel config via `Babel.loadPartialConfigAsync` and the `cacheIdentifier`. The merged Babel config will be determined by the `babel.config.js` or `.babelrc` file if they exist, or the value of the environment variable `BABEL_ENV` and `NODE_ENV`. `cacheIdentifier` can be set to a custom value to force cache busting if the identifier changes.\n\n* `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` -- your project may benefit from this if it transpiles thousands of files.\n\n* `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, but still want to customize.\n\n* `metadataSubscribers`: Default `[]`. Takes an array of context function names. E.g. if you passed ['myMetadataPlugin'], you'd assign a subscriber function to `context.myMetadataPlugin` within your webpack plugin's hooks \u0026 that function will be called with `metadata`. See [`./test/metadata.test.js`](./test/metadata.test.js) for an example.\n\n## Troubleshooting\n\n### Enable debug mode logging\n\nSpecify the webpack option [`stats.loggingDebug`](https://webpack.js.org/configuration/stats/#statsloggingdebug) to output verbose debug logs.\n\n```js\n// webpack.config.js\nmodule.exports = {\n  // ...\n  stats: {\n    loggingDebug: [\"babel-loader\"]\n  }\n}\n```\n\n### babel-loader is slow!\n\nMake sure you are transforming as few files as possible. Because you are probably matching `/\\.m?js$/`, you might be transforming the `node_modules` folder or other unwanted source.\n\nTo exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.\n\nYou can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option. This will cache transformations to the filesystem.\n\n### Some files in my node_modules are not transpiled for IE 11\n\nAlthough we typically recommend not compiling `node_modules`, you may need to when using libraries that do not support IE 11 or any legacy targets.\n\nFor this, you can either use a combination of `test` and `not`, or [pass a function](https://webpack.js.org/configuration/module/#condition) to your `exclude` option. You can also use negative lookahead regex as suggested [here](https://github.com/webpack/webpack/issues/2031#issuecomment-294706065).\n\n```javascript\n{\n    test: /\\.(?:js|mjs|cjs)$/,\n    exclude: {\n      and: [/node_modules/], // Exclude libraries in node_modules ...\n      not: [\n        // Except for a few of them that needs to be transpiled because they use modern syntax\n        /unfetch/,\n        /d3-array|d3-scale/,\n        /@hapi[\\\\/]joi-date/,\n      ]\n    },\n    use: {\n      loader: 'babel-loader',\n      options: {\n        presets: [\n          ['@babel/preset-env', { targets: \"ie 11\" }]\n        ]\n      }\n    }\n  }\n```\n\n### Babel is injecting helpers into each file and bloating my code!\n\nBabel uses very small helpers for common functions such as `_extend`. By default, this will be added to every file that requires it.\n\nYou can instead require the Babel runtime as a separate module to avoid the duplication.\n\nThe following configuration disables automatic per-file runtime injection in Babel, requiring `@babel/plugin-transform-runtime` instead and making all helper references use it.\n\nSee the [docs](https://babeljs.io/docs/plugins/transform-runtime/) for more information.\n\n**NOTE**: You must run `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`.\n\n```javascript\nrules: [\n  // the 'transform-runtime' plugin tells Babel to\n  // require the runtime instead of inlining it.\n  {\n    test: /\\.(?:js|mjs|cjs)$/,\n    exclude: /node_modules/,\n    use: {\n      loader: 'babel-loader',\n      options: {\n        presets: [\n          ['@babel/preset-env', { targets: \"defaults\" }]\n        ],\n        plugins: ['@babel/plugin-transform-runtime']\n      }\n    }\n  }\n]\n```\n\n#### **NOTE**: transform-runtime \u0026 custom polyfills (e.g. Promise library)\n\nSince [@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:\n\n```javascript\n// ...\n        new webpack.ProvidePlugin({\n            'Promise': 'bluebird'\n        }),\n// ...\n```\n\nThe following approach will not work either:\n\n```javascript\nrequire('@babel/runtime/core-js/promise').default = require('bluebird');\n\nvar promise = new Promise;\n```\n\nwhich outputs to (using `runtime`):\n\n```javascript\n'use strict';\n\nvar _Promise = require('@babel/runtime/core-js/promise')['default'];\n\nrequire('@babel/runtime/core-js/promise')['default'] = require('bluebird');\n\nvar promise = new _Promise();\n```\n\nThe previous `Promise` library is referenced and used before it is overridden.\n\nOne approach is to have a \"bootstrap\" step in your application that would first override the default globals before your application:\n\n```javascript\n// bootstrap.js\n\nrequire('@babel/runtime/core-js/promise').default = require('bluebird');\n\n// ...\n\nrequire('./app');\n```\n\n### The Node.js API for `babel` has been moved to `babel-core`.\n\nIf you receive this message, it means that you have the npm package `babel` installed and are using the short notation of the loader in the webpack config (which is not valid anymore as of webpack 2.x):\n```javascript\n  {\n    test: /\\.(?:js|mjs|cjs)$/,\n    loader: 'babel',\n  }\n```\n\nwebpack then tries to load the `babel` package instead of the `babel-loader`.\n\nTo fix this, you should uninstall the npm package `babel`, as it is deprecated in Babel v6. (Instead, install `@babel/cli` or `@babel/core`.)\nIn the case one of your dependencies is installing `babel` and you cannot uninstall it yourself, use the complete name of the loader in the webpack config:\n```javascript\n  {\n    test: /\\.(?:js|mjs|cjs)$/,\n    loader: 'babel-loader',\n  }\n```\n\n### Exclude libraries that should not be transpiled\n\n`core-js` and `webpack/buildin` will cause errors if they are transpiled by Babel.\n\nYou will need to exclude them form `babel-loader`.\n\n```js\n{\n  \"loader\": \"babel-loader\",\n  \"options\": {\n    \"exclude\": [\n      // \\\\ for Windows, / for macOS and Linux\n      /node_modules[\\\\/]core-js/,\n      /node_modules[\\\\/]webpack[\\\\/]buildin/,\n    ],\n    \"presets\": [\n      \"@babel/preset-env\"\n    ]\n  }\n}\n```\n\n### Top level function (IIFE) is still arrow (on Webpack 5)\n\nThat function is injected by Webpack itself _after_ running `babel-loader`. By default Webpack asumes that your target environment supports some ES2015 features, but you can overwrite this behavior using the `output.environment` Webpack option ([documentation](https://webpack.js.org/configuration/output/#outputenvironment)).\n\nTo avoid the top-level arrow function, you can use `output.environment.arrowFunction`:\n\n```js\n// webpack.config.js\nmodule.exports = {\n  // ...\n  output: {\n    // ...\n    environment: {\n      // ...\n      arrowFunction: false, // \u003c-- this line does the trick\n    },\n  },\n};\n```\n\n## Customize config based on webpack target\n\nWebpack supports bundling multiple [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.\n\nFor example, to change the environment targets passed to `@babel/preset-env` based on the webpack target:\n\n```javascript\n// babel.config.js\n\nmodule.exports = api =\u003e {\n  return {\n    presets: [\n      [\n        \"@babel/preset-env\",\n        {\n          useBuiltIns: \"entry\",\n          // caller.target will be the same as the target option from webpack\n          targets: api.caller(caller =\u003e caller \u0026\u0026 caller.target === \"node\")\n            ? { node: \"current\" }\n            : { chrome: \"58\", ie: \"11\" }\n        }\n      ]\n    ]\n  }\n}\n```\n\n## Customized Loader\n\n`babel-loader` exposes a loader-builder utility that allows users to add custom handling\nof Babel's configuration for each file that it processes.\n\n`.custom` accepts a callback that will be called with the loader's instance of\n`babel` so that tooling can ensure that it using exactly the same `@babel/core`\ninstance as the loader itself.\n\nIn cases where you want to customize without actually having a file to call `.custom`, you\nmay also pass the `customize` option with a string pointing at a file that exports\nyour `custom` callback function.\n\n### Example\n\n```js\n// Export from \"./my-custom-loader.js\" or whatever you want.\nmodule.exports = require(\"babel-loader\").custom(babel =\u003e {\n  // Extract the custom options in the custom plugin\n  function myPlugin(api, { opt1, opt2 }) {\n    return {\n      visitor: {},\n    };\n  }\n\n  return {\n    // Passed the loader options.\n    customOptions({ opt1, opt2, ...loader }) {\n      return {\n        // Pull out any custom options that the loader might have.\n        custom: { opt1, opt2 },\n\n        // Pass the options back with the two custom options removed.\n        loader,\n      };\n    },\n\n    // Passed Babel's 'PartialConfig' object.\n    config(cfg, { customOptions }) {\n      if (cfg.hasFilesystemConfig()) {\n        // Use the normal config\n        return cfg.options;\n      }\n\n      return {\n        ...cfg.options,\n        plugins: [\n          ...(cfg.options.plugins || []),\n\n          // Include a custom plugin in the options and passing it the customOptions object.\n          [myPlugin, customOptions],\n        ],\n      };\n    },\n\n    result(result) {\n      return {\n        ...result,\n        code: result.code + \"\\n// Generated by some custom loader\",\n      };\n    },\n  };\n});\n```\n\n```js\n// And in your Webpack config\nmodule.exports = {\n  // ..\n  module: {\n    rules: [{\n      // ...\n      loader: path.join(__dirname, 'my-custom-loader.js'),\n      // ...\n    }]\n  }\n};\n```\n\n### `customOptions(options: Object): { custom: Object, loader: Object }`\n\nGiven the loader's options, split custom options out of `babel-loader`'s\noptions.\n\n\n### `config(cfg: PartialConfig, options: { source, customOptions }): Object`\n\nGiven Babel's `PartialConfig` object, return the `options` object that should\nbe passed to `babel.transform`.\n\n\n### `result(result: Result): Result`\n\nGiven Babel's result object, allow loaders to make additional tweaks to it.\n\n\n## License\n[MIT](https://couto.mit-license.org/)\n","funding_links":["https://github.com/sponsors/babel","https://opencollective.com/babel"],"categories":["JavaScript","[Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript?retiredLocale=it)","Webpack plugins","Plugins"],"sub_categories":["Brunch Plugins","Rspack Loaders"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabel%2Fbabel-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabel%2Fbabel-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabel%2Fbabel-loader/lists"}