ncc 介绍
ncc 是一个简单的 CLI,可以将 Node.js 项目编译为单个文件,包括项目的依赖与 gcc-style。
功能:
设计目标
用法
安装
npm i -g @zeit/ncc
用法
$ ncc build input.js -o dist
输出的Node.js的身体结实input.js成dist/index.js。
执行测试
对于测试和调试,可以将文件构建到临时目录中,并使用以下命令执行完整的源映射支持:
$ ncc run input.js
使用TypeScript
唯一的要求是指ncc到.ts或.tsx文件。一个tsconfig.json 文件是必要的。您很可能希望表明es2015支持:
{ compilerOptions: { target: es2015, moduleResolution: node } }
以编程方式从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], 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) })
当watch: true设置,构建产物不是一个promise,但具有以下特征:
{ // 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 (); }
ncc 官网
https://www.npmjs.com/package/@zeit/ncc
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。