or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api.mdcli.mdindex.md
tile.json

tessl/npm-vercel--ncc

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.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@vercel/ncc@0.38.x

To install, run

npx @tessl/cli install tessl/npm-vercel--ncc@0.38.0

index.mddocs/

@vercel/ncc

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

Package Information

  • Package Name: @vercel/ncc
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install -g @vercel/ncc (CLI) or npm install @vercel/ncc (programmatic)

Core Imports

For programmatic usage:

const ncc = require('@vercel/ncc');

For CLI usage, install globally and use the ncc command directly.

Basic Usage

CLI Usage

# 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 clean

Programmatic Usage

const 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);

Architecture

@vercel/ncc is built around several key components:

  • Webpack Integration: Uses webpack internally for bundling with custom loaders and plugins
  • TypeScript Support: Built-in TypeScript compilation without additional configuration
  • Asset Handling: Automatic asset relocation and bundling for complete standalone builds
  • CLI Interface: Full-featured command-line interface with watch mode and caching
  • Programmatic API: Node.js API for integration into build processes
  • Cache System: Filesystem-based caching for faster subsequent builds

Capabilities

Command Line Interface

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 version

Command Line Interface

Programmatic API

Node.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;
}

Programmatic API

Core Types

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