cf3a34a9b4
* Convert action to ts - Add optional header support - Add optional body support * Small fixes to action.yml and action output * Add node_modules until bundler is added * Add node-fetch * Remove fetch, add axios * Update build * Fix issue with res.status being undefined * Update logging for debug purposes * Attempt to fix missing status code output * Attempt to have code wait for request to finish * Prepare for release - Final cleanup * Allow optional headers & body * v2.0.0 * Add support for environment variables (fixed #17) (#19) * v2.0.0 (#12) - Convert project to Javascript/Typescript - Allow custom headers to be passed in (optional) - Allow body to be optional * Update action.yml * Update action.yml * Add support for environment variables (fixed #17) * Add support for header as environment variables * Run build and package Co-authored-by: Joel Male <joel@joelmale.com> * Bump @actions/core from 1.2.4 to 1.2.5 (#18) Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.4 to 1.2.5. - [Release notes](https://github.com/actions/toolkit/releases) - [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @vercel/ncc from 0.23.0 to 0.24.0 (#16) Bumps [@vercel/ncc](https://github.com/vercel/ncc) from 0.23.0 to 0.24.0. - [Release notes](https://github.com/vercel/ncc/releases) - [Commits](https://github.com/vercel/ncc/compare/0.23.0...0.24.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump prettier from 2.0.5 to 2.1.1 (#15) Bumps [prettier](https://github.com/prettier/prettier) from 2.0.5 to 2.1.1. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.0.5...2.1.1) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * ⬆️ Bump typescript from 3.9.7 to 4.0.2 (#13) Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.9.7 to 4.0.2. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v3.9.7...v4.0.2) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Joel Male <joel@joelmale.com> * v2.0.1 * Add backwards compatibility Co-authored-by: Anand Chowdhary <github@anandchowdhary.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> |
||
---|---|---|
.. | ||
dist | ||
LICENSE | ||
package.json | ||
readme.md |
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
npm i -g @vercel/ncc
Usage
$ ncc <cmd> <opts>
Eg:
$ 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
--license [file] Adds a file containing licensing information to the output
--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:
$ 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('@vercel/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
license: '', // default does not generate a license file
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