Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
Simple CLI for compiling a Node.js module into a single file, together with all its dependencies, gcc-style.
go)npm i -g @vercel/ncc$ ncc <cmd> <opts>Eg:
$ ncc build input.js -o distIf building an .mjs or .js module inside a "type": "module" package boundary, an ES module output will be created automatically.
Outputs the Node.js compact build of input.js into dist/index.js.
Note: If the input file is using a
.cjsextension, then so will the corresponding output file. This is useful for packages that want to use.jsfiles as modules in native Node.js using a"type": "module"in the package.json file.
build <input-file> [opts]
run <input-file> [opts]
cache clean|dir|size
help
version…For testing and debugging, a file can be built into a temporary directory and executed with full source maps support with the command:
$ ncc run input.jsThe only requirement is to point ncc to .ts or .tsx files. A tsconfig.json
file is necessary. Most likely you want to indicate es2015 support:
{
"compilerOptions": {
"target": "es2015",
"moduleResolution": "node"
}
}If typescript is found in devDependencies, that version will be used.
Some packages may need some extra options for ncc support in order to better work with the static analysis.
See package-support.md for some common packages and their usage with ncc.
…When watch: true is set, the build object is not a promise, but has the following signature:
{
// handler re-run on each build completion
// watch errors are reported on "err"
handler (({ err, code, map, assets }) => { ... })
// handler re-run on each rebuild start
rebuild (() => {})
// close the watcher
void close ();
}Build fails with `composite: true` in `tsconfig.json`
Typescript 7 support
target esm instead of commonjs
Are there multiple js files in the directory packaged by NCC?
github/core package fails build because of exports map
Leave dynamic import untouched.
Error: Could not load TypeScript compiler with NPM package name
Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
TypeScript Declarations
ncc build generating multiple index.js files instead of a single bundle after upgrading Node.js