This package provides a command-line interface for the SWC (Speedy Web Compiler) project, a super-fast TypeScript/JavaScript compiler and bundler written in Rust.
npx @tessl/cli install tessl/npm-swc--cli@0.7.0@swc/cli provides command-line interface tools for SWC (Speedy Web Compiler), a super-fast TypeScript/JavaScript compiler and bundler written in Rust. The package offers comprehensive tooling for modern JavaScript development including transpilation, bundling, file watching, and integration with build systems.
npm install @swc/cliThe package provides three main CLI executables rather than library imports:
# Main SWC CLI for compilation
npx swc [options] <files...>
# Experimental binary downloader CLI
npx swcx [options] <files...>
# SWC bundler CLI
npx spack [options]For programmatic usage:
import { swcDir } from "@swc/cli";CommonJS:
const { swcDir } = require("@swc/cli");# Compile a single file
npx swc input.ts -o output.js
# Compile directory with watch mode
npx swc src -d lib --watch
# Bundle with spack
npx spack --entry ./src/index.ts --output dist/
# Use experimental swcx CLI
npx swcx src -d lib@swc/cli is built around three main components:
swc): Core compilation tool with extensive options for TypeScript/JavaScript transpilationspack): Bundling tool powered by SWC's bundling capabilitiesswcx): Next-generation CLI that downloads optimized binariesCore compilation functionality for transforming TypeScript and JavaScript files with extensive configuration options, watch mode, and parallel processing.
// CLI usage: npx swc [options] <files...>
// Programmatic interface
function swcDir(options: {
cliOptions: CliOptions;
swcOptions: Options;
callbacks?: Callbacks;
}): Promise<void>;
interface CliOptions {
outDir: string;
outFile: string;
stripLeadingPaths: boolean;
sync: boolean;
workers: number | undefined;
sourceMapTarget?: string;
filename: string;
filenames: string[];
extensions: string[];
watch: boolean;
copyFiles: boolean;
outFileExtension?: string;
includeDotfiles: boolean;
deleteDirOnStart: boolean;
quiet: boolean;
only: string[];
ignore: string[];
}Bundling functionality that uses SWC's high-performance bundler to create optimized JavaScript bundles from TypeScript and JavaScript sources.
// CLI usage: npx spack [options]
interface SpackCliOptions {
debug: boolean;
}
// Uses @swc/core BundleOptions internallyNext-generation CLI interface that automatically downloads and uses pre-built SWC binaries for optimal performance.
// CLI usage: npx swcx [options] <files...>
function getCoreVersion(): string;
function getBinaryName(): string;
function executeBinary(): Promise<ChildProcess>;
const SWC_CLI_ENV: {
SWCX_CORE_VERSION_OVERRIDE: string;
SWCX_SKIP_CORE_VERSION_CHECK: string;
};interface Callbacks {
readonly onSuccess?: (data: {
duration: number;
compiled?: number;
copied?: number;
filename?: string;
}) => any;
readonly onFail?: (data: {
duration: number;
reasons: Map<string, string>;
}) => any;
readonly onWatchReady?: () => any;
}
enum CompileStatus {
Copied,
Compiled,
Omitted,
Failed,
}
// Re-exports @swc/core types
type Options = import("@swc/core").Options;
type Output = import("@swc/core").Output;