babel-loader lets JavaScript projects transpile source files through Babel inside webpack or Rspack builds. You configure it as a module rule with standard Babel options.
Overview
babel-loader is a loader package that connects Babel to webpack and Rspack so build pipelines can transpile JavaScript and related syntax during bundling. It passes loader options through to Babel, merging them with babel.config.js or .babelrc settings.
Loader-specific options include filesystem caching to speed rebuilds, optional gzip cache compression, custom metadata subscribers, and hooks for advanced customization APIs. Documentation covers troubleshooting slow builds by narrowing which files are matched, excluding node_modules, and using cacheDirectory.
It documents compatibility matrices for babel-loader major versions against webpack, Babel, and Node.js releases. Additional sections explain handling legacy Babel 6 branches, excluding problematic dependencies, customizing presets per webpack target, and building bespoke loaders via the .custom helper.
Output and semantic issues belong to Babel itself; babel-loader focuses on wiring transpilation into module bundlers.
Key features
- Babel integration for webpack
- Rspack compatibility
- Configurable Babel options merge
- Filesystem transpile cache
- Loader-specific customization hooks
- Target-aware preset configuration
- Troubleshooting guidance for builds
Use cases
- Transpiling modern JS in webpack bundles
- Caching Babel output across rebuilds
- Targeting different environments per build
- Custom loader wrappers around Babel