or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdspack.mdswc-cli.mdswcx.md
tile.json

tessl/npm-swc--cli

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.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@swc/cli@0.7.x

To install, run

npx @tessl/cli install tessl/npm-swc--cli@0.7.0

index.mddocs/

@swc/cli

@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.

Package Information

  • Package Name: @swc/cli
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @swc/cli
  • Node Requirement: >= 16.14.0

Core Imports

The 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");

Basic Usage

# 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

Architecture

@swc/cli is built around three main components:

  • Main SWC CLI (swc): Core compilation tool with extensive options for TypeScript/JavaScript transpilation
  • SWC Bundler (spack): Bundling tool powered by SWC's bundling capabilities
  • Experimental CLI (swcx): Next-generation CLI that downloads optimized binaries
  • Programmatic API: Limited programmatic interface for directory compilation

Capabilities

Main SWC CLI Tool

Core 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[];
}

SWC CLI

SWC Bundler

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 internally

SWC Bundler

Experimental SWC CLI

Next-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;
};

Experimental CLI

Types

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;