A template to publish a TypeScript package to npm.
Key features:
- Ready to use ESM build system
- Properly configured exports in package.json to support all modern bundlers and Node.js
- CI with GitHub Actions
- Testing and linting setup ready: Jest, ESLint, Prettier, Knip
- Publish to npm with an npm script, including support for pre-releases (alpha, beta, rc)
npm packvalidation as part of the testing pipeline: makes sure only necessary files are included in the package- Size limit check with size-limit
Included tools:
- Yarn v4
- Rollup
- esbuild
- jest
- prettier
- ESLint
- Knip
- size-limit
- GitHub workflow for tests
- Click "Use this template" button to create a new repository from this template
- Clone the new repository
- Change
package.jsonto your own package name, description, etc. !important: changerepository.urland other repository links to your own repository url - Install dependencies:
yarn(other package managers are not supported) - Write your code in
src/directory - Run
npm run releaseto build and publish your package to npm
- Run
npm testto run all tests (prettier check, typecheck, lint, jest tests, build, package validation withnpm pack, knip) - Run
npm run jest:coverageto run jest with coverage report - Run
npm run jest:watchto run jest in watch mode - Run
npm run sizeto validate package size ornpm run analyzeto see size analysis report
Use release script to publish the package:
npm run release– release a new patch version to npmnpm run release minor– release a new minor version to npmnpm run release major– release a new major version to npmnpm run release minor -- --stage alpha– release a new minor alpha version to npm (for example,1.1.0-alpha.0)
Note that release script will always publish public packages to npm. If you want to publish a private package, change release script in scripts/release.ts.
MIT