A minimal, opinionated starter for building and publishing TypeScript libraries.
- Build ESM and CommonJS bundles with tsdown
- Generate TypeScript declaration files
- Run TypeScript directly with tsx
- Test with Vitest and V8 coverage
- Lint and format with ESLint and
@dhzh/eslint-config - Enforce conventional commits with Commitlint and prek
- Manage releases with bumpp
- Generate GitHub releases from tags with GitHub Actions
- Node.js
^24.18.0 - pnpm
^11.22.0
Use this repository as a template, then install the dependencies:
pnpm installStart the development watcher:
pnpm devThe package entry point is src/index.ts, and tests live in the test directory.
| Command | Description |
|---|---|
pnpm dev |
Run src/index.ts and restart on changes |
pnpm build |
Build ESM, CommonJS, and declaration files into dist |
pnpm build:dev |
Rebuild the package in watch mode |
pnpm test |
Run the test suite once |
pnpm test:dev |
Run tests in watch mode |
pnpm test:coverage |
Run tests and generate a coverage report |
pnpm lint |
Check the project with ESLint |
pnpm lint-fix |
Fix lint and formatting issues |
pnpm version:update |
Check and update dependency versions |
pnpm release |
Select and create a new package version and Git tag |
pnpm release:publish |
Create a release and publish the package to npm |
Running pnpm build generates:
dist/
├── index.cjs
├── index.d.cts
├── index.d.mts
└── index.mjs
The package exposes both ESM and CommonJS entry points through the exports field in package.json.
Before you start coding with this template:
- Update
README.mdfor your project. - Update the
name,version,description,author,license,homepage,keywords, andrepositoryfields inpackage.json. - Update the license information in
LICENSE. - Remove the
.githubdirectory if you do not want to use the included GitHub workflows. - Replace the example code in
srcandtestwith your implementation and tests. - If you want to publish the package to npm, add a
prepackscript to build the package before publishing:
{
"scripts": {
"prepack": "pnpm build"
}
}The default release workflow creates a GitHub release whenever a tag matching v* is pushed.
An npm publishing workflow is provided as .github/workflows/publish.yml.template. Rename it to publish.yml to enable it, then configure npm trusted publishing for your GitHub repository.
Only dist is included in the published package, so make sure the package is built before publishing.