zyz-ts-library-example 中文文档教程
发布到 npm
tsc
npm publish
后续版本
# make a path / bugfix
npm version patch
# make a new feture
npm version minor
# make a breaking change
npm version major
使用
npm install --save zyz-ts-library-example
消耗
import { sayHello } from "zyz-ts-library-example";
sayHello();
使用 npm 链接在本地测试模块
使用 npm链接您可以轻松测试您的更改是否正常工作。
cd unit-test
npm run linklib
npm test
这里 npm run linklib 只是 npm run --prefix ../library-starter build && 的别名。 npm 链接 ../library-starter。
在 github 上查看演示库的完整源代码:https://github.com/bersling/typescript-library-starter。
上述教程包含构建和构建所需的所有步骤。发布工作库。但是,您可能还应该包含一些单元测试,并且您可能希望首先在本地测试库的行为,而不需要发布。以下是更多相关资源:
Publish to npm
tsc
npm publish
subsequent releases
# make a path / bugfix
npm version patch
# make a new feture
npm version minor
# make a breaking change
npm version major
usage
npm install --save zyz-ts-library-example
consume
import { sayHello } from "zyz-ts-library-example";
sayHello();
Testing your module locally with npm link
Using npm link you can easily test whether your changes are working correctly.
cd unit-test
npm run linklib
npm test
Here npm run linklib
is just an alias for npm run --prefix ../library-starter build && npm link ../library-starter
.
Check out the full source of the demo library on github: https://github.com/bersling/typescript-library-starter.
The above tutorial contains all the steps necessary to build & publish a working library. However, you should probably also include some unit tests and you might want to test the behavior of your library locally first, without publishing. Here are some more resources for this:
How to unit test your library How to set up a local consumer without publishing to npm How to make your library available as a system command