Babel is a JavaScript compiler. Use next generation JavaScript, today.
open sourceMITself-hostablefree
Babel is a JavaScript compiler that turns code written with the newest syntax into JavaScript that older browsers and runtimes can run, with source maps for debugging the output. It is built out of plugins, grouped into presets: @babel/preset-env picks the transforms for the environments you target, and other presets convert JSX and strip TypeScript or Flow type annotations. Missing built-ins come from a polyfill library such as core-js, and the same plugin API powers codemods and other source transformations. A small group of volunteers maintains it, funded through Open Collective.
Ways to install
Package managers
Problems it solves
- write modern JavaScript and still ship code that runs in older browsers
- compile JSX in a React project without a full framework toolchain
- strip TypeScript types during the build without slowing it down with type checking
- use a proposed JavaScript feature before browsers support it
- only transform the syntax my target browsers don't understand, based on a browserslist
- write a codemod that rewrites thousands of files across a large JavaScript codebase
- add my own compile-time transform to the JavaScript build, like stripping debug calls
- debug transpiled JavaScript in the browser and see my original source lines
- our bundle ships arrow functions and optional chaining that an old Safari can't parse
- parse JavaScript into an AST and print it back after changing it
- set up the transpile step that webpack or Jest runs on each file
- insert polyfills only for the features a browser is missing
Features
- syntax transforms from newer JavaScript to ES5
- @babel/preset-env targets chosen environments
- JSX transform with @babel/preset-react
- strips TypeScript and Flow type annotations
- polyfills through core-js
- plugins and presets you can write yourself
- source maps
- codemods and other source transformations
- assumptions that trade spec compliance for smaller or faster output
- command line compiler (@babel/cli)
Limitations
- Doesn't type-check TypeScript or Flow: it strips the type annotations, so you still run tsc or Flow to check types2
Capabilities
| Has an API | plan not known |
|---|---|
| Has a command line tool | plan not known |
| Takes plugins | plan not known |
Alternatives
The same job
These do what Babel does.
