简体中文 | English
Set up an npm package project skeleton by running one command.
- Use jest as build-in test Framework。
- Building source code by rollup。
Creating a lib project by run:
npx lib-candy new LIB-NAME
example:
npx lib-candy new my-third-lib
LIB-NAME is not only project folder name, but also package name as default. Once the creating process is done, directory structure will be:
my-third-lib
├── doc
| └── api.md
├── CHANGELOG.md
├── README.md
├── node_modules
├── package-lock.json
├── package.json
└── src
└── index.js
you can open your project folder:
cd my-third-lib
Inside the newly created project, you can run some built-in commands:
Build the same code for CommonJS,ES module and UMD。see input/output convention:
- Input entry js must be
src/index.js
。 - Commonjs output can be specify with
main
property inpackage.json
, if not specified, default value isLIB-NAME/lib/index.js
. - ES module output can be specify with
module
property inpackage.json
, if not specified, default value isLIB-NAME/es/index.js
. - UMD output can be specify with
browser
property inpackage.json
, if not specified, default value isLIB-NAME/umd/index.js
.umdName
property inpackage.json
must be set, if UMD output is desired when building.
example:
{
"name": "my-third-lib",
"main": "./lib/index.js",
"module": "./es/index.js",
"browser": "./umd/index.js",
"umdName": "MyThirdLib",
}
Use babel plugin to build lib source code. Supported syntax please refer @babel/env
. You can also describe the environments you support/target for your lib:
browserslist
This can be a browserslist-compatible query.engines.node
Node version your lib support.
example:
{
"browserslist": "> 0.25%, not dead",
"engines": {
"node": ">= 0.12.0"
}
}
Build will not include any polyfill except regenerator in terms of lib size。regeneratorRuntime: true | false
in package.json
can determine whether regenerator polyfill will be include in output code(default is false).
Underlying test framework is Jest,Please refer to jestjs.io about writing test case.
You need Node8.10.0 or later vesion.