This package provides a zero-configuration CLI tool for compiling Node.js modules into single files along with all their dependencies, similar to how gcc works for compiled languages.
npx @tessl/cli install tessl/npm-vercel--ncc@0.38.0@vercel/ncc is a simple CLI tool and Node.js library for compiling Node.js modules into single files with all their dependencies bundled together. It provides zero-configuration bundling for Node.js applications, similar to how gcc works for compiled languages, enabling minimal deployments and faster startup times for serverless environments.
npm install -g @vercel/ncc (CLI) or npm install @vercel/ncc (programmatic)For programmatic usage:
const ncc = require('@vercel/ncc');For CLI usage, install globally and use the ncc command directly.
# Build a Node.js module into a single file
ncc build input.js -o dist
# Run a module with source maps for development
ncc run input.js
# Clean build cache
ncc cache cleanconst ncc = require('@vercel/ncc');
// Compile a module
const { code, map, assets } = await ncc('/path/to/input.js', {
minify: false,
sourceMap: false,
externals: ['some-external-module']
});
// Write the compiled code
require('fs').writeFileSync('dist/index.js', code);@vercel/ncc is built around several key components:
Full-featured CLI with support for building, running, and cache management. Includes options for minification, source maps, watch mode, and external dependency handling.
ncc <command> [options]
Commands:
build <input-file> [opts] # Compile input file to output directory
run <input-file> [opts] # Build and execute file with source maps
cache clean|dir|size # Cache management operations
help # Show usage information
version # Show ncc versionNode.js API for integrating ncc into build processes and tools. Supports all CLI features plus additional programmatic options like custom webpack configurations and asset handling.
const ncc: (entry: string, options?: NccOptions) => Promise<NccResult> | NccWatcher;
interface NccOptions {
cache?: string | boolean;
externals?: string[] | { [key: string]: string };
minify?: boolean;
sourceMap?: boolean;
assetBuilds?: boolean;
watch?: boolean;
// ... additional options
}
interface NccResult {
code: string;
map?: string;
assets: { [filename: string]: { source: Buffer | string; permissions: number } };
symlinks: { [path: string]: string };
stats: any;
}interface NccOptions {
/** Custom cache path or disable caching */
cache?: string | boolean;
/** Custom asset emission function */
customEmit?: (path: string) => boolean | void;
/** Enable ES module output */
esm?: boolean;
/** External modules to exclude from bundling */
externals?: string[] | { [key: string]: string };
/** Output filename (default: 'index.js') */
filename?: string;
/** Enable minification */
minify?: boolean;
/** Generate source maps */
sourceMap?: boolean;
/** Include source-map-support */
sourceMapRegister?: boolean;
/** Source map base prefix */
sourceMapBasePrefix?: string;
/** Build nested JS assets recursively */
assetBuilds?: boolean;
/** Enable watch mode */
watch?: boolean;
/** Enable V8 compile cache */
v8cache?: boolean;
/** Directory filter for assets */
filterAssetBase?: string;
/** List of existing asset names */
existingAssetNames?: string[];
/** Disable build summaries */
quiet?: boolean;
/** Enable debug logging */
debugLog?: boolean;
/** Use TypeScript transpile-only mode */
transpileOnly?: boolean;
/** License file output */
license?: string;
/** ECMAScript target version */
target?: string;
/** Production mode */
production?: boolean;
/** Package.json main fields resolution order */
mainFields?: string[];
}
interface NccResult {
/** Compiled JavaScript code */
code: string;
/** Source map JSON string (if enabled) */
map?: string;
/** Asset files with their content and permissions */
assets: { [filename: string]: { source: Buffer | string; permissions: number } };
/** Symbolic links mapping */
symlinks: { [path: string]: string };
/** Webpack compilation statistics */
stats: any;
}
interface NccWatcher {
/** Set build completion handler */
handler(callback: (result: NccResult & { err?: any }) => void): void;
/** Set rebuild start handler */
rebuild(callback: () => void): void;
/** Close the watcher */
close(): void;
}