TypeScript Package Template
The TypeScript Package template provides a lightweight package development setup for pure TypeScript libraries. Use it for infrastructure packages such as HTTP clients, storage adapters, utilities, SDKs, and other framework-agnostic modules. For Vue SFC components, use the Component template instead.
Technical Stack
- TypeScript - Type-safe package development (docs)
- tsup - Bundles ESM, CJS, source maps, and type declarations (docs)
- ESBuild - Fast transform pipeline used by tsup (docs)
- pnpm workspace - Runs as an app template inside the monorepo
Quick Start
1. Create Project
bash
vup init my-project
cd my-project
vup add my-package
# Select Package template2. Install Dependencies
bash
pnpm install3. Start Development
bash
cd apps/my-package
pnpm devProject Structure
txt
apps/my-package/
├── src/
│ ├── http/
│ │ └── index.ts # Example infrastructure module
│ └── index.ts # Root barrel export
├── tsup.config.ts # Build entries and output config
├── tsconfig.json # TypeScript config
├── package.json # Package metadata and exports
└── README.mdModule Conventions
- Put each reusable capability in its own directory, such as
src/http/,src/socket/, orsrc/storage/. - Export public types and functions from each module entry.
- Keep
src/index.tsas the root aggregation entry. - When adding a subpath import, update both
tsup.config.tsentries andpackage.jsonexports.
Example imports:
typescript
import { http } from 'your-package';
import { HttpClient } from 'your-package/http';Build Outputs
The template builds into .output/:
txt
.output/
├── index.js
├── index.cjs
├── index.d.ts
└── http/
├── index.js
├── index.cjs
└── index.d.tspackage.json maps each public entry explicitly:
json
{
"exports": {
".": {
"types": "./.output/index.d.ts",
"import": "./.output/index.js",
"require": "./.output/index.cjs"
},
"./http": {
"types": "./.output/http/index.d.ts",
"import": "./.output/http/index.js",
"require": "./.output/http/index.cjs"
}
}
}Scripts
bash
pnpm dev
pnpm type-check
pnpm build
pnpm lint
pnpm format:checkPublishing
Before publishing, check:
package.jsonhas the correctname,version,exports, and runtime dependencies.pnpm type-checkpasses.pnpm buildgenerates ESM, CJS, and.d.tsfiles.- The package only exposes stable public entries.
bash
pnpm publish:npm
pnpm publish:beta