jpskill.com
🛠️ 開発・MCP コミュニティ

tsup

TypeScriptライブラリをesbuildで高速にバンドルし、設定不要でnpmパッケージとして公開、ESM/CJS両対応、宣言ファイル生成、tree-shakingまでカバーするSkill。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

TypeScriptライブラリをesbuildで高速にバンドルし、設定不要でnpmパッケージとして公開、ESM/CJS両対応、宣言ファイル生成、tree-shakingまでカバーするSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o tsup.zip https://jpskill.com/download/15498.zip && unzip -o tsup.zip && rm tsup.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15498.zip -OutFile "$d\tsup.zip"; Expand-Archive "$d\tsup.zip" -DestinationPath $d -Force; ri "$d\tsup.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して tsup.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → tsup フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

tsup

概要

tsup は、npm パブリッシング用の TypeScript ライブラリをバンドルします。設定は不要で、esbuild (tsc より 100 倍高速) を利用しています。ESM + CJS デュアルパッケージを出力し、.d.ts 宣言ファイルを生成し、ツリーシェイキングを処理します。2025 年以降の TypeScript パッケージを構築するための標準的なツールです。

どのような時に使うか

  • TypeScript ライブラリを npm に公開する場合
  • ESM と CJS の両方の出力が必要な場合 (デュアルパッケージ)
  • モノレポで内部パッケージを構築する場合
  • Rollup/Webpack を設定せずに高速なビルドを行いたい場合
  • バンドルされた出力と一緒に .d.ts ファイルを生成する場合

手順

セットアップ

npm install -D tsup typescript

設定不要

// package.json — 最小限の設定
{
  "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 — ビルド設定
import { defineConfig } from "tsup";

export default defineConfig({
  entry: ["src/index.ts"],
  format: ["esm", "cjs"],       // デュアル ESM + CJS 出力
  dts: true,                     // .d.ts ファイルを生成
  splitting: true,               // ESM のためのコード分割
  clean: true,                   // ビルド前に dist/ をクリーン
  treeshake: true,               // 未使用コードを削除
  sourcemap: true,
  minify: false,                 // ライブラリは minify しない
  outDir: "dist",
});

複数のエントリーポイント

// tsup.config.ts — サブパスエクスポートを持つライブラリ
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 — サブパスエクスポート
{
  "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" }
  }
}

環境固有のビルド

// tsup.config.ts — ブラウザと Node 向けの異なるビルド
import { defineConfig } from "tsup";

export default defineConfig([
  {
    entry: ["src/index.ts"],
    format: ["esm"],
    platform: "browser",          // ブラウザ向け最適化
    globalName: "MyLib",
    outDir: "dist/browser",
  },
  {
    entry: ["src/index.ts"],
    format: ["esm", "cjs"],
    platform: "node",             // Node.js 向け最適化
    target: "node18",
    outDir: "dist/node",
    dts: true,
  },
]);

例 1: TypeScript ユーティリティライブラリの公開

ユーザープロンプト: 「TypeScript ユーティリティ関数のコレクションがあります。ESM と CJS のサポートを使用して npm 用にパッケージ化してください。」

エージェントは、デュアル出力のために tsup を構成し、package.json の exports を設定し、型宣言を生成し、npm 公開の準備をします。

例 2: React コンポーネントライブラリの構築

ユーザープロンプト: 「TypeScript 型とツリーシェイキングを使用して React コンポーネントライブラリをバンドルしてください。」

エージェントは、React external、コンポーネントごとの複数のエントリーポイント、CSS 処理、および宣言ファイル生成を使用して tsup を設定します。

ガイドライン

  • format: ["esm", "cjs"] — 最大限の互換性のために常に両方を同梱してください
  • dts: true — TypeScript 宣言を生成します (別のプロセスを使用します)
  • clean: true — dist/ 内の古いファイルを防ぎます
  • ライブラリを minify しない — 消費者の bundler に処理させます
  • external for peer deps — React、Vue などをバンドルしないでください
  • splitting for ESM — 消費者のためのツリーシェイキングを有効にします
  • package.json の exports — 最新の Node.js 解決、types 条件を最初に
  • files: ["dist"] — ビルドされた出力のみを公開します
  • treeshake: true — 出力から内部の未使用コードを削除します
  • ウォッチモード — 開発には tsup --watch を使用します
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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 modetsup --watch for development