@zeit/ncc
[![Build Status](https://circleci.com/gh/zeit/ncc.svg?&style=shield)](https://circleci.com/gh/zeit/workflows/ncc) [![codecov](https://codecov.io/gh/zeit/ncc/branch/master/graph/badge.svg)](https://codecov.io/gh/zeit/ncc)
Last updated 8 days ago by styfle .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @zeit/ncc 
SYNC missed versions from official npm registry.

ncc

Build Status codecov

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

npm i -g @zeit/ncc

Usage

$ ncc build input.js -o dist

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

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:

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

{
  "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 for some common packages and their usage with ncc.

Programmatically From Node.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:

{
  // 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. Dynamic non-statically analyzable asset loads may not work out correctly

Current Tags

  • 0.19.0-beta.1                                ...           beta (4 months ago)
  • 0.1.14                                ...           canary (10 months ago)
  • 0.20.5                                ...           latest (8 days ago)

71 Versions

  • 0.20.5                                ...           8 days ago
  • 0.20.4                                ...           2 months ago
  • 0.20.3                                ...           3 months ago
  • 0.20.2                                ...           3 months ago
  • 0.20.1                                ...           3 months ago
  • 0.20.0                                ...           3 months ago
  • 0.19.1                                ...           3 months ago
  • 0.19.0                                ...           3 months ago
  • 0.19.0-beta.1                                ...           4 months ago
  • 0.18.5                                ...           4 months ago
  • 0.18.4                                ...           4 months ago
  • 0.18.3                                ...           4 months ago
  • 0.18.2                                ...           5 months ago
  • 0.18.1                                ...           5 months ago
  • 0.18.0                                ...           5 months ago
  • 0.17.4                                ...           5 months ago
  • 0.17.3                                ...           6 months ago
  • 0.17.2                                ...           6 months ago
  • 0.17.1                                ...           6 months ago
  • 0.17.0                                ...           6 months ago
  • 0.16.1                                ...           6 months ago
  • 0.16.0                                ...           6 months ago
  • 0.15.2                                ...           7 months ago
  • 0.15.1                                ...           7 months ago
  • 0.15.0                                ...           7 months ago
  • 0.14.0                                ...           8 months ago
  • 0.13.3                                ...           8 months ago
  • 0.13.2                                ...           8 months ago
  • 0.13.1                                ...           8 months ago
  • 0.13.0                                ...           8 months ago
  • 0.12.1                                ...           8 months ago
  • 0.12.0                                ...           8 months ago
  • 0.11.0                                ...           8 months ago
  • 0.9.0                                ...           8 months ago
  • 0.8.1                                ...           9 months ago
  • 0.8.0                                ...           9 months ago
  • 0.7.0                                ...           9 months ago
  • 0.6.0                                ...           9 months ago
  • 0.5.5                                ...           9 months ago
  • 0.5.4                                ...           9 months ago
  • 0.5.3                                ...           9 months ago
  • 0.5.2                                ...           9 months ago
  • 0.5.1                                ...           9 months ago
  • 0.5.0                                ...           9 months ago
  • 0.4.1                                ...           9 months ago
  • 0.4.0                                ...           9 months ago
  • 0.3.0                                ...           9 months ago
  • 0.2.1                                ...           9 months ago
  • 0.2.0                                ...           10 months ago
  • 0.1.18                                ...           10 months ago
  • 0.1.17                                ...           10 months ago
  • 0.1.16                                ...           10 months ago
  • 0.1.15                                ...           10 months ago
  • 0.1.14                                ...           10 months ago
  • 0.1.13                                ...           10 months ago
  • 0.1.12                                ...           10 months ago
  • 0.1.11                                ...           10 months ago
  • 0.1.10                                ...           10 months ago
  • 0.1.9                                ...           10 months ago
  • 0.1.8                                ...           10 months ago
  • 0.1.7                                ...           10 months ago
  • 0.1.6                                ...           10 months ago
  • 0.1.5-webpack                                ...           10 months ago
  • 0.1.4-webpack                                ...           10 months ago
  • 0.1.3-webpack                                ...           10 months ago
  • 0.1.2-webpack                                ...           10 months ago
  • 0.1.1-webpack                                ...           10 months ago
  • 0.0.4                                ...           10 months ago
  • 0.0.3                                ...           10 months ago
  • 0.0.2                                ...           10 months ago
  • 0.0.1                                ...           10 months ago
Downloads
Today 1
This Week 16
This Month 266
Last Day 4
Last Week 144
Last Month 531
Dependencies (0)
None
Dev Dependencies (91)

Copyright 2014 - 2017 © taobao.org |