babel-compile
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
A CLI tool built on babel-core for compiling .js/.jsx files to ES6 with automatic source map generation, output directory cleaning, and configuration loading from NPM modules. Version 2.0.0 is the current stable release with low release cadence. It provides an alternative to the Babel CLI for batch compilation with extra features like source maps with correct file references and cleaning the output directory to avoid stale files. It requires a Babel preset (e.g., babel-preset-es2015).
Common errors
error Error: Cannot find module 'babel-preset-es2015' ↓
cause babel-compile requires an explicit preset to be installed; it does not ship with one.
fix
Run: npm install babel-preset-es2015 --save-dev
error SyntaxError: Unexpected token import ↓
cause Compiled output may still contain ES6 features if a preset is not provided or configured correctly.
fix
Ensure babel-preset-es2015 (or appropriate preset) is installed and passed via -p option.
Warnings
gotcha Source maps require Node >=0.12 or source-map-support module for proper stack traces. ↓
fix Install source-map-support and require it in your entry point.
gotcha The tool only works with .js and .jsx files; other extensions are ignored. ↓
fix Rename files to .js or .jsx, or use a different compiler.
Install
npm install babel-compile yarn add babel-compile pnpm add babel-compile Imports
- babel-compile (CLI) wrong
require('babel-compile')correctnpx babel-compile -p es2015 src:lib - compile function (internal)
Not intended for direct import; use CLI only.
Quickstart
npm install babel-compile --save-dev
npm install babel-preset-es2015 --save-dev
# Add to package.json scripts:
# "compile": "babel-compile -p es2015 src:lib"
# Run:
npm run compile