About this project
ncc is a command-line tool maintained by Vercel that bundles a Node.js program together with all of its dependencies into a single output file, in the spirit of gcc-style compilation. Its design goal is zero configuration: point it at an entry file and it produces a compact build, with TypeScript handled natively when a tsconfig.json is present.
The primary commands are `build` (emit a bundled file to an output directory, defaulting to `dist/index.js`), `run` (build into a temporary directory and execute with full source-map support for testing and debugging), and `cache` (clean, inspect, or size the build cache). Options cover common bundling needs: `--minify`, `--source-map`, `--external` to skip bundling specific modules, `--watch` for incremental rebuilds, `--target` to set the ECMAScript output level, `--v8-cache` to emit a V8 compile cache, `--license` to attach licensing information, `--stats-out` to dump webpack stats as JSON, and `--asset-builds` to recursively bundle nested JS assets such as worker scripts. Module format is inferred from the input, so `.mjs` inputs or files inside a `"type": "module"` package boundary produce ES module output, while `.cjs` inputs preserve the CommonJS extension.
Beyond the CLI, ncc exposes a programmatic API from Node.js. Calling `require('@vercel/ncc')` with an input path and an options object returns a promise resolving to `{ code, map, assets }`, where assets is a map of file names to their source, permissions, and symlink metadata. Options mirror the CLI flags, including custom cache paths, externals, minification, source maps, watch mode, license generation, and target selection. In watch mode the returned object exposes `handler`, `rebuild`, and `close` callbacks instead of a promise.
The project's stated motivations are publishing minimal npm packages, shipping only relevant code to serverless environments, avoiding bundler configuration overhead, and improving boot time and I/O. It targets Node.js programs as both input and output and aims to support all Node.js patterns and npm modules. A documented caveat is that file and asset relocation relies on a static evaluator, so dynamically loaded assets that cannot be statically analyzed may not be relocated correctly. Some packages require extra options for full compatibility, which are catalogued in the repository's package-support documentation.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.