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

babel-compiler.mddocs/

Babel Compiler

The main babel command provides comprehensive JavaScript compilation with file and directory processing, source map generation, and watch mode capabilities.

Capabilities

File Compilation

Compiles individual JavaScript files with full Babel transformation pipeline.

/**
 * Compile JavaScript files using Babel transformations
 * Command: babel [options] file1.js file2.js ...
 * 
 * Core file compilation options:
 * --out-file, -o [file]: Output to specific file
 * --source-maps [type]: Generate source maps (true|false|inline|both)
 * --source-root [path]: Set source root for source maps
 */

Usage Examples:

# Compile single file to stdout
babel script.js

# Compile file to specific output
babel script.js --out-file dist/script.js

# Compile with inline source maps
babel script.js --out-file dist/script.js --source-maps inline

# Compile multiple files into one
babel src/a.js src/b.js --out-file dist/bundle.js

Directory Compilation

Processes entire directories with recursive file handling and output structure preservation.

/**
 * Compile directory of JavaScript files
 * Command: babel [options] src-dir
 * 
 * Directory compilation options:
 * --out-dir, -d [dir]: Output directory
 * --copy-files, -D: Copy non-compilable files
 * --extensions, -x [list]: File extensions to process [.es6,.js,.es,.jsx]
 */

Usage Examples:

# Compile directory
babel src --out-dir lib

# Compile with file copying
babel src --out-dir lib --copy-files

# Compile specific extensions
babel src --out-dir lib --extensions ".ts,.tsx,.js"

Watch Mode

Automatic recompilation when source files change, with configurable file watching.

/**
 * Watch files for changes and recompile automatically
 * Options:
 * --watch, -w: Enable watch mode
 * --skip-initial-build: Skip compilation on startup
 * 
 * Requires either --out-file or --out-dir
 */

Usage Examples:

# Watch and compile to directory
babel src --out-dir lib --watch

# Watch without initial build
babel src --out-dir lib --watch --skip-initial-build

# Watch single file
babel script.js --out-file dist/script.js --watch

Source Map Generation

Comprehensive source map support for debugging transformed code.

/**
 * Source map generation options:
 * --source-maps [type]: Generate source maps
 *   - true: External .map files
 *   - false: No source maps (default)
 *   - inline: Inline source maps in output
 *   - both: Both external and inline
 * --source-root [path]: Source root for source map paths
 */

Usage Examples:

# External source maps
babel src --out-dir lib --source-maps

# Inline source maps
babel src --out-dir lib --source-maps inline

# Both external and inline
babel src --out-dir lib --source-maps both

Babel Configuration Options

All babel-core options are dynamically supported by the CLI.

/**
 * Babel transformation options (from babel-core):
 * --presets [list]: Babel presets to use
 * --plugins [list]: Babel plugins to use
 * --ignore [patterns]: Files/directories to ignore
 * --only [patterns]: Only transform files matching patterns
 * --compact [boolean]: Compact output
 * --minified [boolean]: Minify output
 * --comments [boolean]: Include comments in output
 * --retain-lines [boolean]: Retain line numbers
 */

Usage Examples:

# Use specific presets
babel src --out-dir lib --presets es2015,react

# Ignore specific files
babel src --out-dir lib --ignore "**/*.test.js"

# Only process specific files
babel src --out-dir lib --only "src/**/*.js"

File Processing Control

Options for controlling which files are processed and how.

/**
 * File processing options:
 * --extensions, -x [list]: Extensions to compile [.es6,.js,.es,.jsx]
 * --copy-files, -D: Copy non-compilable files to output
 * --quiet, -q: Suppress logging output
 */

Usage Examples:

# Process TypeScript files
babel src --out-dir lib --extensions ".ts,.js"

# Copy all files, compile supported ones
babel assets --out-dir dist --copy-files

# Silent compilation
babel src --out-dir lib --quiet

STDIN/STDOUT Processing

The babel command can process input from stdin and output to stdout for pipeline integration.

/**
 * STDIN processing:
 * babel [options] < input.js > output.js
 * 
 * When no input files specified, reads from stdin
 * Outputs to stdout unless --out-file specified
 */

Usage Examples:

# Process from stdin
echo "const x = () => 42;" | babel

# Pipeline processing
cat source.js | babel --presets es2015 > compiled.js

Error Handling and Validation

The babel command performs comprehensive validation and error handling.

/**
 * Validation rules:
 * - Cannot use both --out-file and --out-dir
 * - --watch requires --out-file or --out-dir
 * - --skip-initial-build requires --watch
 * - Input files must exist
 * - Output directory must be writable
 * 
 * Error types:
 * - Syntax errors with code frames
 * - File access errors
 * - Configuration validation errors
 * - Transform plugin errors
 */

The command exits with code 2 for validation errors and code 1 for compilation errors.

File Extension Handling

Babel CLI processes files based on extension patterns and compilation capability.

/**
 * Default supported extensions: ['.es6', '.js', '.es', '.jsx']
 * Custom extensions via --extensions flag
 * 
 * File processing logic:
 * - Compilable files: Transformed with Babel
 * - Non-compilable files: Copied if --copy-files enabled
 * - Hidden files: Ignored by default
 * - Ignored patterns: Skipped based on --ignore option
 */