# @zeit/ncc

> [![CI Status](https://github.com/zeit/ncc/workflows/CI/badge.svg)](https://github.com/zeit/ncc/actions?workflow=CI) [![codecov](https://codecov.io/gh/zeit/ncc/branch/master/graph/badge.svg)](https://codecov.io/gh/zeit/ncc)

Latest version **0.22.3** (published 2020-05-22) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @zeit/ncc
pnpm add @zeit/ncc
yarn add @zeit/ncc
bun add @zeit/ncc
```

Provides the command `ncc`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.22.3 |
| Published | 2020-05-22 |
| First published | 2018-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9842 |
| Maintainers | alexaltea, anatrajkovska, andybitz, arunoda, arzafran, atcastle, caarlos0, chibicode, cleishm, codetheory, coetry, dav-is, developit, fivepointseven, gielcobben, gmonaco, guybedford, housseindjirdeh, iamevilrabbit, igorklopov, ijjk, janicklas-ralph, jaredpalmer, javivelasco, jkrems, joecohens, juancampa, keanulee, kikobeats, leo, lfades, lucleray, matheuss, maxleiter, mfix22, mglagola, msweeneydev, nazarenooviedo, nkzawa, paco, paulogdm, prateekbh, quietshu, rabaut, ragojose, rauchg, samsisle, sarupbanskota, skllcrn, spanicker, styfle, timer, timneutkens, tootallnate, umegaya, williamli, zeit-bot |

## Links

- npm: https://www.npmjs.com/package/@zeit/ncc
- Repository: https://github.com/zeit/ncc
- Homepage: https://github.com/zeit/ncc#readme
- Issues: https://github.com/zeit/ncc/issues
- npm.io page: https://npm.io/package/@zeit/ncc

## Recent versions

- 0.22.3 (latest) — 2020-05-22
- 0.19.0-beta.1 (beta) — 2019-05-15
- 0.1.14 (canary) — 2018-11-26
- 0.22.2 — 2020-05-18
- 0.22.1 — 2020-04-05
- 0.22.0 — 2020-03-23
- 0.21.1 — 2020-02-12
- 0.21.0 — 2020-01-04
- 0.20.5 — 2019-09-09
- 0.20.4 — 2019-07-02
- 0.20.3 — 2019-07-02
- 0.20.2 — 2019-06-26
- 0.20.1 — 2019-06-19
- 0.20.0 — 2019-06-18
- 0.19.1 — 2019-06-13
- … 62 more at https://npm.io/package/@zeit/ncc/versions

## README

# ncc

[![CI Status](https://github.com/zeit/ncc/workflows/CI/badge.svg)](https://github.com/zeit/ncc/actions?workflow=CI)
[![codecov](https://codecov.io/gh/zeit/ncc/branch/master/graph/badge.svg)](https://codecov.io/gh/zeit/ncc)

Simple CLI for compiling a Node.js module into a single file,
together with all its dependencies, gcc-style.

## Motivation

- Publish minimal packages to npm
- Only ship relevant app code to serverless environments
- Don't waste time configuring bundlers
- Generally faster bootup time and less I/O overhead
- Compiled language-like experience (e.g.: `go`)

## Design goals

- Zero configuration
- TypeScript built-in
- Only supports Node.js programs as input / output
- Support all Node.js patterns and npm modules

## Usage

### Installation
```bash
npm i -g @zeit/ncc
```

### Usage

```bash
$ ncc <cmd> <opts>
```
Eg:
```bash
$ ncc build input.js -o dist
```

Outputs the Node.js compact build of `input.js` into `dist/index.js`.

> Note: If the input file is using a `.cjs` extension, then so will the corresponding output file.
> This is useful for packages that want to use `.js` files as modules in native Node.js using
> a `"type": "module"` in the package.json file.

#### Commands:
```
  build <input-file> [opts]
  run <input-file> [opts]
  cache clean|dir|size
  help
  version
```

#### Options:
```
  -o, --out [file]         Output directory for build (defaults to dist)
  -m, --minify             Minify output
  -C, --no-cache           Skip build cache population
  -s, --source-map         Generate source map
  --no-source-map-register Skip source-map-register source map support
  -e, --external [mod]     Skip bundling 'mod'. Can be used many times
  -q, --quiet              Disable build summaries / non-error outputs
  -w, --watch              Start a watched build
  --v8-cache               Emit a build using the v8 compile cache
  --stats-out [file]       Emit webpack stats as json to the specified output file
```

### Execution Testing

For testing and debugging, a file can be built into a temporary directory and executed with full source maps support with the command:

```bash
$ ncc run input.js
```

### With TypeScript

The 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:

```json
{
  "compilerOptions": {
    "target": "es2015",
    "moduleResolution": "node"
  }
}
```

### Package Support

Some packages may need some extra options for ncc support in order to better work with the static analysis.

See [package-support.md](package-support.md) for some common packages and their usage with ncc.

### Programmatically From Node.js

```js
require('@zeit/ncc')('/path/to/input', {
  // provide a custom cache path or disable caching
  cache: "./custom/cache/path" | false,
  // externals to leave as requires of the build
  externals: ["externalpackage"],
  // directory outside of which never to emit assets
  filterAssetBase: process.cwd(), // default
  minify: false, // default
  sourceMap: false, // default
  sourceMapBasePrefix: '../', // default treats sources as output-relative
  // when outputting a sourcemap, automatically include
  // source-map-support in the output file (increases output by 32kB).
  sourceMapRegister: true, // default
  watch: false, // default
  v8cache: false, // default
  quiet: false, // default
  debugLog: false // default
}).then(({ code, map, assets }) => {
  console.log(code);
  // Assets is an object of asset file names to { source, permissions, symlinks }
  // expected relative to the output code (if any)
})
```

When `watch: true` is set, the build object is not a promise, but has the following signature:

```js
{
  // 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 ();
}
```

## Caveats

- Files / assets are relocated based on a [static evaluator](https://github.com/zeit/webpack-asset-relocator-loader#how-it-works). Dynamic non-statically analyzable asset loads may not work out correctly

---
_Source: https://npm.io/package/@zeit/ncc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
