We compile and run in one go
ncc, a simple Node.js CLI program and API for compiling Node.js projects into a single JavaScript file.go, that export a static ELF binary file, ncc will output a self-contained script that bundles all its dependencies by leveraging webpack.npm i -g @zeit/ncc
ncc compiler, which has been compiled with ncc itself.cd myapp npm i chalk
index.js:const chalk = require("chalk"); console.log(chalk.blue.bgRed.bold("Hello world!"));
ncc run it:We compile and run in one go
ncc build it for production:We output the final version to the dist directory
ncc implements a go-style API and design philosophy. Compiling a program should be intuitive, single-command, zero-configuration.ncc help or check out the api docs.Deploying a very large dependency tree in just 950kb
apollo-server-express, express, graphql and all their sub-dependencies.node_modules alone amounts to 35 times the size of our bundle:It is said that node_modules is one of the heaviest objects in the universe. ncc is therefore anti-gravity.
ncc makes deployment faster and more secure, by only shipping the necessary code to production.ncc development, it used to bundle webpack as a regular npm dependency. It eventually became good enough to self-host.ncc version:In most of our tests, ncc would take between 15 and 30 seconds to install
ncc version (usually 5-10x faster):The installation performance of ncc is solely bound by your download speed
require("ncc") (which requires webpack, a very large amount of JavaScript).require src/index.js, where every subsequent require invokes file-system lookups.Just importing code can be remarkably slow in Node.js, compared to native programs
ncc and minify we consistently see a 50% improvement in boot-up performance, which will only get faster.Faster, but there is still a lot of room for improvement
ncc is already quite fast, even though no optimizations have been made.ncc run and default on for ncc build. Developers might want to opt out of this feature when debugging programs or dependencies.ncc will favor safety over maximally optimal minification.go's example, we intend for ncc to transparently ensure dependencies have been installed, by executing yarn install or npm install automatically.git pull node my-program
git pull the dependencies (package.json, yarn.lock, package-lock.json) might have changed.git pull ncc run my-program
.ts[x] extensions:ncc build my-app.ts
v8-compile-cache have successfully made programs like yarn (which is distributed as a single-file, in the same spirit as ncc) up two 2x faster.ncc is that it yields an output directory containing one or more files. Typically it's one, but we also perform static analysis on synchronous filesystem reads.pdkfit and its dependencies read a lot of files that are bundled with their packages upon initialization:ncc is capable of emitting dependencies, such as statically analyzable file-system lookups
.node files, making ncc a complete solution that supports the vast majority of npm modules in the ecosystem out of the box.ncc run is optional, but it has the following current and future benefits:ncc build. While ncc gets remarkably close to
the native node semantics (with many integration tests) from time to time some modules with unusually-dynamic dependencies or filesystem reads could give it trouble.ncc, by taking any JavaScript source(s) and bundling them into an executable that bundles the Node.js runtime inside. While ncc outputs scripts (text), pkg outputs executables (binary).