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.
—
Next-generation CLI interface that automatically downloads and uses pre-built SWC binaries for optimal performance. This experimental tool provides the same functionality as the main SWC CLI but with improved performance through native binary execution.
The experimental SWC CLI that downloads and executes optimized pre-built binaries.
npx swcx [options] <files...>
# Supports all the same options as the main swc CLI:
-d, --out-dir [out] # Compile to output directory
-o, --out-file [out] # Compile to single output file
-w, --watch # Watch for file changes
-s, --source-maps [type] # Generate source maps
-q, --quiet # Suppress compilation output
# ... and all other swc optionsUsage Examples:
# Basic compilation (same as swc)
npx swcx src/index.ts -o lib/index.js
# Directory compilation with watch mode
npx swcx src -d lib --watch
# All swc CLI options are supported
npx swcx src -d lib --source-maps --workers 4Control swcx behavior through environment variables.
const SWC_CLI_ENV: {
/** Override the SWC core version to use */
SWCX_CORE_VERSION_OVERRIDE: "SWCX_CORE_VERSION_OVERRIDE";
/** Skip automatic version checking */
SWCX_SKIP_CORE_VERSION_CHECK: "SWCX_SKIP_CORE_VERSION_CHECK";
};Environment Examples:
# Use specific SWC version
SWCX_CORE_VERSION_OVERRIDE=1.3.50 npx swcx src -d lib
# Skip version checking
SWCX_SKIP_CORE_VERSION_CHECK=1 npx swcx src -d lib
# Combined usage
SWCX_CORE_VERSION_OVERRIDE=1.3.50 SWCX_SKIP_CORE_VERSION_CHECK=1 npx swcx src -d libAutomatically determine the appropriate SWC core version to use.
/**
* Determine the SWC core version to use based on project configuration
*
* Priority order:
* 1. SWCX_CORE_VERSION_OVERRIDE environment variable
* 2. @swc/core version from local package.json dependencies
* 3. Latest available version at CLI publish time
*
* @returns SWC core version string
*/
function getCoreVersion(): string;Version Detection Logic:
SWCX_CORE_VERSION_OVERRIDE if set@swc/core version from local package.jsonHandle platform-specific binary downloads and execution.
/**
* Get the platform-specific binary name for SWC
*
* Supports:
* - Windows: x64, ia32, arm64 (MSVC)
* - macOS: x64, arm64
* - Linux: x64, arm64, arm (GNU/musl detection)
*
* @returns Platform-specific binary filename
* @throws Error if platform/architecture is unsupported
*/
function getBinaryName(): string;
/**
* Check if the system uses musl libc (Alpine Linux, etc.)
* @returns True if musl libc is detected
*/
function isMusl(): boolean;
/**
* Download SWC binary and execute with provided arguments
*
* Process:
* 1. Determine SWC version and platform binary name
* 2. Download binary from GitHub releases if not cached
* 3. Cache binary in node_modules/.bin/swc-cli-{version}
* 4. Execute binary with forwarded command-line arguments
*
* @returns Promise resolving to spawned child process
*/
function executeBinary(): Promise<ChildProcess>;Binary Download Process:
https://github.com/swc-project/swc/releases/download/v{version}/{binary}node_modules/.bin/swc-cli-{version}/Supported platforms and architectures:
type PlatformBinaryMap = {
win32: {
x64: "swc-win32-x64-msvc.exe";
ia32: "swc-win32-ia32-msvc.exe";
arm64: "swc-win32-arm64-msvc.exe";
};
darwin: {
x64: "swc-darwin-x64";
arm64: "swc-darwin-arm64";
};
linux: {
x64: "swc-linux-x64-gnu" | "swc-linux-x64-musl";
arm64: "swc-linux-arm64-gnu" | "swc-linux-arm64-musl";
arm: "swc-linux-arm64-gnu";
};
};Common error scenarios and handling:
// Unsupported platform error
throw new Error(
`Unsupported platform: binary ${binaryName} for '${platform} ${arch}' is not available`
);
// Version detection warnings
console.warn(
`Failed to determine swc core version from package.json, using latest available version ${latestVersion} instead`,
error
);
// Binary download/execution errors are handled by bin-wrapperswcx provides performance improvements over the main CLI:
Switching from swc to swcx:
# Before (traditional CLI)
npx swc src -d lib --watch
# After (experimental CLI)
npx swcx src -d lib --watch
# All options remain the same
npx swcx src -d lib --source-maps --workers 4 --extensions .ts,.tsxPackage.json Integration:
{
"scripts": {
"build": "swcx src -d lib",
"build:watch": "swcx src -d lib --watch",
"build:prod": "swcx src -d lib --source-maps"
}
}type ChildProcess = import("child_process").ChildProcess;
type StdioOptions = import("child_process").StdioOptions;
interface PlatformBinaryMap {
[platform: string]: {
[arch: string]: string;
};
}
const SWC_CLI_ENV: {
SWCX_CORE_VERSION_OVERRIDE: "SWCX_CORE_VERSION_OVERRIDE";
SWCX_SKIP_CORE_VERSION_CHECK: "SWCX_SKIP_CORE_VERSION_CHECK";
};Install with Tessl CLI
npx tessl i tessl/npm-swc--cli