tsup

使用 tsup 零配置基于 esbuild 打包 TypeScript 库,适用于构建 npm 包、发布到 npm 和生成 ESM/CJS 双格式及声明文件,支持 tree-shaking 的库打包场景。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
7

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "tsup":https://skillpi.com/zh/skills/deepskill-4eca984283b490a5cc6ed3ac5db617f04a04f224637b22a30fc4b319fc4e02db。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

使用 tsup 零配置基于 esbuild 打包 TypeScript 库,适用于构建 npm 包、发布到 npm 和生成 ESM/CJS 双格式及声明文件,支持 tree-shaking 的库打包场景。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

适合谁
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: tsup
description: >-
  Bundle TypeScript libraries with tsup — zero-config, powered by esbuild.
  Use when someone asks to "bundle a TypeScript library", "build npm package",
  "tsup", "publish TypeScript to npm", "build ESM and CJS", "bundle with
  esbuild", or "library bundling with zero config". Covers ESM/CJS dual
  output, declaration files, tree-shaking, and npm publishing.
license: Apache-2.0
compatibility: "Node.js 18+. TypeScript."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: devops
  tags: ["bundling", "typescript", "tsup", "esbuild", "library"]

tsup

Overview

tsup bundles TypeScript libraries for npm publishing — zero config, powered by esbuild (100x faster than tsc). Outputs ESM + CJS dual packages, generates .d.ts declaration files, and handles tree-shaking. The standard tool for building TypeScript packages in 2025+.

When to Use

  • Publishing a TypeScript library to npm
  • Need both ESM and CJS output (dual package)
  • Building internal packages in a monorepo
  • Want fast builds without configuring Rollup/Webpack
  • Generating .d.ts files alongside bundled output

Instructions

Setup

npm install -D tsup typescript

Zero Config

// package.json — Minimal setup
{
  "name": "my-lib",
  "version": "1.0.0",
  "type": "module",
  "main": "./dist/index.cjs",
  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
      "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
    }
  },
  "files": ["dist"],
  "scripts": {
    "build": "tsup",
    "dev": "tsup --watch"
  }
}
// tsup.config.ts — Build configuration
import { defineConfig } from "tsup";

export default defineConfig({
  entry: ["src/index.ts"],
  format: ["esm", "cjs"],       // Dual ESM + CJS output
  dts: true,                     // Generate .d.ts files
  splitting: true,               // Code splitting for ESM
  clean: true,                   // Clean dist/ before build
  treeshake: true,               // Remove unused code
  sourcemap: true,
  minify: false,                 // Don't minify libraries
  outDir: "dist",
});

Multiple Entry Points

// tsup.config.ts — Library with subpath exports
import { defineConfig } from "tsup";

export default defineConfig({
  entry: {
    index: "src/index.ts",
    client: "src/client.ts",
    server: "src/server.ts",
    utils: "src/utils/index.ts",
  },
  format: ["esm", "cjs"],
  dts: true,
  clean: true,
});
// package.json — Subpath exports
{
  "exports": {
    ".": { "import": "./dist/index.js", "require": "./dist/index.cjs" },
    "./client": { "import": "./dist/client.js", "require": "./dist/client.cjs" },
    "./server": { "import": "./dist/server.js", "require": "./dist/server.cjs" },
    "./utils": { "import": "./dist/utils.js", "require": "./dist/utils.cjs" }
  }
}

Environment-Specific Builds

// tsup.config.ts — Different builds for browser and Node
import { defineConfig } from "tsup";

export default defineConfig([
  {
    entry: ["src/index.ts"],
    format: ["esm"],
    platform: "browser",          // Browser-optimized
    globalName: "MyLib",
    outDir: "dist/browser",
  },
  {
    entry: ["src/index.ts"],
    format: ["esm", "cjs"],
    platform: "node",             // Node.js optimized
    target: "node18",
    outDir: "dist/node",
    dts: true,
  },
]);

Examples

Example 1: Publish a TypeScript utility library

User prompt: "I have a collection of TypeScript utility functions. Package them for npm with ESM and CJS support."

The agent will configure tsup for dual output, set up package.json exports, generate type declarations, and prepare for npm publish.

Example 2: Build a React component library

User prompt: "Bundle my React component library with TypeScript types and tree-shaking."

The agent will set up tsup with React external, multiple entry points per component, CSS handling, and declaration file generation.

Guidelines

  • format: ["esm", "cjs"] — always ship both for maximum compatibility
  • dts: true — generate TypeScript declarations (uses a separate process)
  • clean: true — prevent stale files in dist/
  • Don't minify libraries — let the consumer's bundler handle it
  • external for peer deps — don't bundle React, Vue, etc.
  • splitting for ESM — enables tree-shaking for consumers
  • exports in package.json — modern Node.js resolution, types condition first
  • files: ["dist"] — only publish the built output
  • treeshake: true — remove internal unused code from output
  • Watch mode — tsup --watch for development

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值88/100

亮点

  • 解决 TypeScript 库打包与发布的开发者高频刚需场景
  • 涵盖 ESM/CJS 双输出、声明文件生成、Tree-shaking 等完整功能闭环
触发精准95/100

亮点

  • 触发词精准覆盖多种用户表达变体,边界清晰无歧义
结构规范92/100

亮点

  • 步骤划分清晰,包含完整端到端示例和配置模板
  • frontmatter 完整,文档结构规范易读
执行可靠88/100

亮点

  • 工具来源明确,参数配置正确,覆盖主要使用场景和异常情况
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 37 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。