or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

babel-compiler.mdbabel-doctor.mdbabel-node.mdexternal-helpers.mdindex.md
tile.json

tessl/npm-babel-cli

Command-line interface for Babel JavaScript compiler with file watching, directory compilation, and Node.js integration.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-cli@6.26.x

To install, run

npx @tessl/cli install tessl/npm-babel-cli@6.26.0

index.mddocs/

Babel CLI

Babel CLI is the command-line interface for Babel, a JavaScript compiler that transforms ES6+ code into backwards-compatible JavaScript. It provides multiple executable commands for compiling JavaScript files, running Node.js with Babel transformation, and generating external helper functions.

Package Information

  • Package Name: babel-cli
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev babel-cli

Core Imports

The babel-cli package primarily provides CLI commands rather than importable modules. The main entry point throws an error directing users to use babel-core instead:

// This will throw an error:
require('babel-cli'); // throws "Use the `babel-core` package not `babel`."

For programmatic usage, use babel-core:

const babel = require('babel-core');

Basic Usage

Babel CLI provides several command-line tools for different use cases:

# Compile a single file
babel script.js

# Compile a file to a specific output
babel script.js --out-file compiled.js

# Compile a directory
babel src --out-dir lib

# Watch files and recompile on changes
babel src --out-dir lib --watch

# Run Node.js with Babel transformation
babel-node script.js

# Generate external helpers
babel-external-helpers --output-type global

Architecture

Babel CLI consists of several key components:

  • CLI Commands: Multiple executable commands (babel, babel-node, babel-external-helpers)
  • File Processing: Single file and directory compilation with source map support
  • Watch Mode: File system watching for automatic recompilation
  • Node.js Integration: babel-node for running Node.js with Babel preprocessing
  • Helper Generation: External helper function generation for optimized builds

Capabilities

Main Babel Compiler

The primary babel command for compiling JavaScript files and directories with comprehensive transformation options.

// Command: babel [options] <files ...>
// Main options:
// --out-file, -o [out]: Compile all input files into a single file
// --out-dir, -d [out]: Compile an input directory of modules into an output directory
// --watch, -w: Recompile files on changes
// --extensions, -x [extensions]: List of extensions to compile [.es6,.js,.es,.jsx]
// --copy-files, -D: When compiling a directory copy over non-compilable files
// --source-maps: Generate source maps (true|false|inline|both)
// --quiet, -q: Don't log anything

Babel Compiler

Babel Node

Node.js integration that allows running scripts with Babel transformation applied in real-time.

// Command: babel-node [options] [ -e script | script.js ] [arguments]
// Options:
// --eval, -e [script]: Evaluate script
// --print, -p [code]: Evaluate script and print result
// --only, -o [globs]: Only transform files matching globs
// --ignore, -i [globs]: Ignore files matching globs
// --extensions, -x [extensions]: List of extensions to hook into [.es6,.js,.es,.jsx]
// --plugins, -w [string]: Babel plugins to use
// --presets, -b [string]: Babel presets to use

Babel Node

External Helpers

Utility for generating external Babel helper functions to reduce code duplication in compiled output.

// Command: babel-external-helpers [options]
// Options:
// --whitelist, -l [whitelist]: Whitelist of helpers to ONLY include
// --output-type, -t [type]: Type of output (global|umd|var), default: global

External Helpers

Babel Doctor (Deprecated)

The babel-doctor command has been removed and is no longer available. It throws an error when invoked.

// Command: babel-doctor
// Status: DEPRECATED/REMOVED
// Behavior: Throws error "babel-doctor has been removed."

Babel Doctor

Types

interface CompilationOptions {
  filename?: string;
  sourceFileName?: string;
  sourceMapTarget?: string;
  sourceMaps?: boolean | 'inline' | 'both';
  sourceRoot?: string;
  ignore?: RegExp[];
  only?: RegExp[];
  plugins?: string[];
  presets?: string[];
}

interface CompilationResult {
  code: string;
  map?: object;
  ignored?: boolean;
  filename?: string;
  actual?: string;
}

interface FileProcessingOptions {
  outFile?: string;
  outDir?: string;
  watch?: boolean;
  copyFiles?: boolean;
  extensions?: string[];
  quiet?: boolean;
  skipInitialBuild?: boolean;
}

Error Handling

Babel CLI handles various error scenarios:

  • Syntax Errors: Displays code frames with error location
  • File Access Errors: Graceful handling of missing files or permissions
  • Configuration Errors: Clear error messages for invalid options
  • Watch Mode Errors: Continues watching even if individual files fail to compile

Common errors include:

  • babel-doctor has been removed - The babel-doctor command is deprecated
  • Use the 'babel-core' package not 'babel' - When trying to require babel-cli as a module
  • --watch requires --out-file or --out-dir - Watch mode needs an output target
  • cannot have --out-file and --out-dir - Conflicting output options