Skip to content

Repository files navigation

starter-typescript

A minimal, opinionated starter for building and publishing TypeScript libraries.

Features

  • 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

Requirements

  • Node.js ^24.18.0
  • pnpm ^11.22.0

Getting Started

Use this repository as a template, then install the dependencies:

pnpm install

Start the development watcher:

pnpm dev

The package entry point is src/index.ts, and tests live in the test directory.

Scripts

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

Package Output

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.

Usage

Before you start coding with this template:

  1. Update README.md for your project.
  2. Update the name, version, description, author, license, homepage, keywords, and repository fields in package.json.
  3. Update the license information in LICENSE.
  4. Remove the .github directory if you do not want to use the included GitHub workflows.
  5. Replace the example code in src and test with your implementation and tests.
  6. If you want to publish the package to npm, add a prepack script to build the package before publishing:
{
  "scripts": {
    "prepack": "pnpm build"
  }
}

Publishing

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.

License

MIT

About

A simple code template for TypeScript developing.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages