Back to TypeScript

ts-library

typescriptlibrarymonorepobuild-toolingpackage-exportsapi-designvitestrelease-workflow
⭐ 682πŸ•’ 2026-06-01Source β†—

Install this skill

npx skills add onmax/nuxt-skills

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

This skill provides a structured framework for building maintainable, high-performance TypeScript libraries. It synthesizes architectural standards observed in modern ecosystems like Vite, Vitest, and Zod. Instead of manually configuring complex build chains, you get a standardized approach to dual-format packaging (CJS and ESM) and precise TypeScript configuration. The skill enforces ESM-first principles while ensuring legacy compatibility, tree-shakable output, and type-safe API patterns. It prioritizes build speed and developer ergonomics by advocating for tools like tsdown and unbuild over manual Babel or Rollup configurations. By focusing on modern resolution strategies and standardized export conditions, this skill helps authors ship packages that work reliably across diverse runtime environments, from Node.js to edge computing, without common pitfalls like missing types or broken import conditions.

When to Use This Skill

  • β€’Developing a utility library intended for both browser and Node.js environments
  • β€’Refactoring an existing project to support modern module systems
  • β€’Setting up a release pipeline for a new open-source TypeScript package
  • β€’Designing type-safe builder patterns for public-facing SDKs

How to Invoke This Skill

Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:

  • β€œHow should I structure my TypeScript library for dual-format output?
  • β€œConfigure my library to support both ESM and CJS correctly
  • β€œWhat is the best build tool for a modern TypeScript package?
  • β€œHelp me set up tree-shaking for my TS project
  • β€œHow to handle exports in package.json for a TypeScript library?

Pro Tips

  • πŸ’‘Combine this skill with 'documentation-generation' to ensure your well-designed APIs are clearly documented for consumers.
  • πŸ’‘For complex API design challenges, iterate with the skill, asking for examples for different patterns (e.g., 'show me a factory pattern example for a plugin API').
  • πŸ’‘When troubleshooting build issues, use the skill to compare your `tsconfig` and build tool configurations against recommended best practices from popular libraries.

What this skill does

  • β€’Configuring package.json for dual ESM and CJS compatibility
  • β€’Optimizing tsconfig.json for modern bundler resolution
  • β€’Selecting appropriate build pipelines using tsdown or unbuild
  • β€’Implementing tree-shakable API architectures
  • β€’Automating library test suites with Vitest

When not to use it

  • βœ•Developing specialized Nuxt modules (use the nuxt-modules skill instead)
  • βœ•Small, single-file scripts that do not require packaging or distribution

Example workflow

  1. Initialize project structure following ESM-first principles
  2. Configure tsconfig.json with Bundler module resolution
  3. Define package.json exports to handle CJS and ESM consumers
  4. Select and configure a build tool like tsdown or unbuild
  5. Write and run unit tests using Vitest
  6. Implement automated release workflows for npm publishing

Prerequisites

  • –Familiarity with standard TypeScript syntax
  • –Basic understanding of npm/yarn/pnpm package management

Pitfalls & limitations

  • !Ignoring the impact of sideEffects: false on code tree-shaking
  • !Using outdated module resolutions that break modern bundlers
  • !Forgetting to include declaration files in package exports

FAQ

Why is ESM-first recommended?
Modern runtimes and bundlers perform better with ESM, and it prevents common compatibility issues when sharing code across environments.
Should I use tsdown or unbuild?
Use tsdown for simple, high-speed builds and unbuild for more complex scenarios that require advanced path resolution or multi-file outputs.
Do I need to support CJS?
While ESM is preferred, supporting both ensures your library remains functional in legacy Node.js environments, increasing your potential user base.

How it compares

This skill replaces fragmented, outdated blog post advice with validated, consistent patterns derived from current industry-leading libraries.

Source & trust

⭐ 682 starsπŸ•’ Updated 2026-06-01
πŸ“„ Full skill instructions β€” original source: onmax/nuxt-skills
# TypeScript Library Development

Patterns for authoring high-quality TypeScript libraries, extracted from studying unocss, shiki, unplugin, vite, vitest, vueuse, zod, trpc, drizzle-orm, and more.

## When to Use

- Starting a new TypeScript library (single or monorepo)
- Setting up package.json exports for dual CJS/ESM
- Configuring tsconfig for library development
- Choosing build tools (tsdown, unbuild)
- Designing type-safe APIs (builder, factory, plugin patterns)
- Writing advanced TypeScript types
- Setting up vitest for library testing
- Configuring release workflow and CI

**For Nuxt module development:** use nuxt-modules skill

## Quick Reference

| Working on... | Load file |
| --------------------- | ------------------------------------------------------------------ |
| New project setup | [references/project-setup.md](references/project-setup.md) |
| Package exports | [references/package-exports.md](references/package-exports.md) |
| tsconfig options | [references/typescript-config.md](references/typescript-config.md) |
| Build configuration | [references/build-tooling.md](references/build-tooling.md) |
| API design patterns | [references/api-design.md](references/api-design.md) |
| Type inference tricks | [references/type-patterns.md](references/type-patterns.md) |
| Testing setup | [references/testing.md](references/testing.md) |
| Release workflow | [references/release.md](references/release.md) |
| CI/CD setup | [references/ci-workflows.md](references/ci-workflows.md) |

## Key Principles

- ESM-first: "type": "module" with .mjs outputs
- Dual format: always support both CJS and ESM consumers
- moduleResolution: "Bundler" for modern TypeScript
- tsdown for most builds, unbuild for complex cases
- Smart defaults: detect environment, don't force config
- Tree-shakeable: lazy getters, proper sideEffects: false

_Token efficiency: Main skill ~300 tokens, each reference ~800-1200 tokens_

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/ts-library/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/onmax/nuxt-skills/ts-library/SKILL.md
  • Cursor: ~/.cursor/skills/onmax/nuxt-skills/ts-library/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/onmax/nuxt-skills/ts-library/SKILL.md

πŸš€ Install with CLI:
npx skills add onmax/nuxt-skills

Read the Master Guide: Mastering Agent Skills β†’

Related Skill Units

Recommended Rules

View more rules β†’

Recommended Workflows

View more workflows β†’

Recommended MCP Servers

View more MCP servers β†’

Take It Further

Maximize your productivity with these powerful resources

πŸ“‹

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
πŸ“–

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid typescript issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under TypeScript and is published by Onmax, maintained in onmax/nuxt-skills.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.