# vite-plugin-babel

> Runs Babel in Vite during all commands

Latest version **1.7.3** (published 2026-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-babel
pnpm add vite-plugin-babel
yarn add vite-plugin-babel
bun add vite-plugin-babel
```

## Health

**Score 50/100 (C)** — status: active.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.7.3 |
| Published | 2026-05-19 |
| First published | 2022-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 68 |
| Author | Miłosz Mandowski |
| Maintainers | przyb, f0rsaken |
| Keywords | vite-plugin, vite, babel |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-babel
- Repository: https://github.com/owlsdepartment/vite-plugin-babel
- Homepage: https://github.com/owlsdepartment/vite-plugin-babel#readme
- Issues: https://github.com/owlsdepartment/vite-plugin-babel/issues
- npm.io page: https://npm.io/package/vite-plugin-babel

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.7.3 (latest) — 2026-05-19
- 2.0.0-rc.2 (next) — 2026-05-13
- 1.7.2 — 2026-05-19
- 1.7.1 — 2026-05-15
- 1.7.0 — 2026-05-13
- 1.6.0 — 2026-03-19
- 1.5.1 — 2026-02-09
- 1.5.0 — 2026-02-08
- 1.4.1 — 2026-01-13
- 1.4.0 — 2026-01-13
- 1.3.2 — 2025-06-26
- 1.3.1 — 2025-04-29
- 1.3.0 — 2024-12-04
- 1.2.0 — 2023-12-18
- 1.1.3 — 2023-01-09
- … 5 more at https://npm.io/package/vite-plugin-babel/versions

## README

# Vite Plugin Babel

Run Babel during any Vite command, also during serve.

## Motivations

Most Vite plugins runs Babel only during `build`, not `serve`, and only other possible way to do this is via [@vitejs/plugin-react](https://www.npmjs.com/package/@vitejs/plugin-react). ESBuild is awesome tool, but doesn't support some experimental features, like decorators ([issue #2349](https://github.com/vitejs/vite/issues/2349)) or class instance fields, out of box. You can use them in TypeScript, but not pure JS. This plugin was made to enable usage of such features and runs babel during `optimizeDeps`, `dev` and `build` stages, but it can be configured.

## Installation

```bash
# yarn
yarn add -D vite-plugin-babel

# npm
npm install -D vite-plugin-babel
```

## Usage

Add it to your Vite config

```js
import { defineConfig } from 'vite';
import babel from 'vite-plugin-babel';

export default defineConfig({
    plugins: [
        // Babel will try to pick up Babel config files (.babelrc / .babelrc.* / babel.config.*)
        babel(),
        // ...
    ],

    // ...
})
```

## Config

Babel config can be either passed to `babelConfig` field or via Babel config file. For all babel options see: [Babel Options](https://babeljs.io/docs/en/options).

By default, babel is run for JS/JSX files (`include` defaults to `/\.jsx?$/`). To scope it to other files, set `include` / `exclude` and add the matching Babel presets/plugins to `babelConfig` yourself.

> **Migrating from 1.6.x:** in 1.7.0 the default of `include` changed from `undefined` to `/\.jsx?$/`. If you previously relied on `filter` alone to scope files, set `include` explicitly to your desired scope — `filter` is now combined with `include` as an AND, so it can only narrow further, not expand. `filter` is deprecated; prefer `include` / `exclude`.

| Name | Type | Default | Description |
|---|---|---|---|
| `apply` | `'serve' \| 'build' \| (config: UserConfig, env: ConfigEnv) => boolean` | `undefined` | Limits plugin usage to only build or only serve. If not specified, will be run during both cycles. Same as [`apply` in Vite Plugins API](https://vite.dev/guide/api-plugin.html#conditional-application) |
| `enforce` | `'pre' \| 'post'` | `pre` | Force plugin's order execution. More details: [Vite Plugin Ordering](https://vite.dev/guide/api-plugin.html#plugin-ordering) |
| `babelConfig` | `object` | `{}` | [Babel Transform Options](https://babeljs.io/docs/en/options) |
| `include` | `string \| RegExp \| Array<string\|RegExp>` | `/\.jsx?$/` | Which files to include. Defaults to `.js` / `.jsx`. Set explicitly to scope to other extensions — the matching Babel presets/plugins are your responsibility. |
| `exclude` | `string \| RegExp \| Array<string\|RegExp>` | `undefined` | Which files to exclude. Takes priority over `include`. |
| `filter` | `RegExp \| (id: string) => boolean` | `undefined` | **Deprecated.** Combined with `include` as an AND — can only narrow further, not expand. Prefer `include` / `exclude`. |
| `loader` | `Loader` or `(path: string) => Loader` | `undefined` | **Vite 7 and lower** This tells esbuild how to interpret the contents after babel's transformation. For example, the js loader interprets the contents as JavaScript and the css loader interprets the contents as CSS. The loader defaults to js if it's not specified. See the [Content Types](https://esbuild.github.io/content-types) page for a complete list of all built-in loaders. |
| `optimizeOnSSR` | `boolean` | `false` | Run dependency optimization during SSR. Could be useful when running a project on a cloud workers, like `@cloudflare/vite-plugin` |

## Tips

Vite team didn't enable and include Babel by default, because they wanted to keep experience as fast as possible and esbuild can already do a lot of things, you would probably do with Babel. Because of that, we recommend to only include those Babel plugins you really need. You can use option `babelConfig.configFile` and omit Babel config file usage:

```js
babel({
    babelConfig: {
        plugins: ['@babel/plugin-proposal-decorators']
    }
})
```

or just use [Babel config file](https://babeljs.io/docs/config-files).

__NOTE:__ Any babel plugins and presets need to be installed seperately and are not included with this package.

## Troubleshooting

#### [ERROR] The JSX syntax extension is not currently enabled

This usually happens when you're using this plugin to only transform part of a `.jsx` file (such as decorators), and leaving the JSX syntax untouched. By default, esbuild interprets contents as `.js`, so you'll need to specify the loader esbuild should use.

Example:

```js
import { extname } from 'path';
// ...
babel({
    babelConfig: {
        plugins: ['@babel/plugin-proposal-decorators'],

        // uses the jsx loader for .jsx files
        loader: path => {
          if (extname(path) === '.jsx') {
            return 'jsx';
          }
        },
    }
})
```

## License

Library is under [MIT License](LICENSE)

---
_Source: https://npm.io/package/vite-plugin-babel · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
