Linux command
ncc 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Compile Node.js project
ncc build [src/index.js]
Compile with output directory
ncc build [src/index.js] -o [dist/]
Compile with minification
ncc build [src/index.js] -m
Compile with source maps
ncc build [src/index.js] -s
Compile and watch
ncc build [src/index.js] -w
Run directly
ncc run [src/index.js]
Compile TypeScript
ncc build [src/index.ts]
说明
ncc (Node.js Compiler Collection) compiles Node.js projects into a single file. It bundles code and dependencies, producing portable output that runs without node_modules. The compiler handles CommonJS and ES modules, automatically resolving imports. Native modules and assets are extracted alongside the bundle. TypeScript and modern JavaScript features are transpiled automatically. The output targets Node.js, maintaining compatibility with Node's module system. Externals keep specific packages out of the bundle. This is useful for native modules that can't be bundled or for reducing size when dependencies are available at runtime. Minification reduces output size. Source maps enable debugging of bundled code by mapping back to original sources. Watch mode recompiles on file changes, useful during development.
参数
- build _FILE_
- Compile to single file.
- run _FILE_
- Compile and run.
- -o _DIR_
- Output directory.
- -m, --minify
- Minify output.
- -s, --source-map
- Generate source maps.
- -w, --watch
- Watch for changes.
- -e, --external _PKG_
- Keep package external.
- -a, --asset-builds
- Emit asset files separately.
- --license _FILE_
- Output license file.
- -q, --quiet
- Quiet mode.
- -v, --version
- Show version.
FAQ
What is the ncc command used for?
ncc (Node.js Compiler Collection) compiles Node.js projects into a single file. It bundles code and dependencies, producing portable output that runs without node_modules. The compiler handles CommonJS and ES modules, automatically resolving imports. Native modules and assets are extracted alongside the bundle. TypeScript and modern JavaScript features are transpiled automatically. The output targets Node.js, maintaining compatibility with Node's module system. Externals keep specific packages out of the bundle. This is useful for native modules that can't be bundled or for reducing size when dependencies are available at runtime. Minification reduces output size. Source maps enable debugging of bundled code by mapping back to original sources. Watch mode recompiles on file changes, useful during development.
How do I run a basic ncc example?
Run `ncc build [src/index.js]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does build _FILE_ do in ncc?
Compile to single file.