Skip to content
build-tools logo

Build Tools Skill

build-tools

Build tool configuration for tsup, tsx, and bundlers. Use when setting up build pipelines.

SKILL.md

Full skill instructions

Build Tools Skill

This skill covers build tool configuration for TypeScript projects.

When to Use

Use this skill when:

  • Setting up build pipelines
  • Configuring library bundling
  • Running TypeScript directly
  • Choosing between build tools

Core Principle

RIGHT TOOL FOR THE JOB - Use tsup for libraries, tsx for scripts, Vite for apps.

Tool Selection Guide

Use CaseRecommended Tool
Library/​Packagetsup
CLI Applicationtsup + tsx
Script Executiontsx
React SPAVite
Full-Stack AppNext.js

tsup - Library Bundler

Installation

npm install -D tsup

Basic Configuration

// tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['src/​index.ts'],
  format: ['esm', 'cjs'],
  dts: true,
  clean: true,
  splitting: false,
  sourcemap: true,
  minify: false,
  treeshake: true,
});

Package.json for Library

{
  "name": "my-library",
  "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"
  }
}

Multiple Entry Points

// tsup.config.ts
export default defineConfig({
  entry: {
    index: 'src/​index.ts',
    utils: 'src/​utils/​index.ts',
    cli: 'src/​cli.ts',
  },
  format: ['esm', 'cjs'],
  dts: true,
});

CLI with Shebang

// tsup.config.ts
export default defineConfig({
  entry: ['src/​cli.ts'],
  format: ['esm'],
  banner: {
    js: '#!/​usr/​bin/​env node',
  },
  clean: true,
});

tsx - TypeScript Execution

Installation

npm install -D tsx

Usage

# Run TypeScript file directly
npx tsx src/​script.ts

# Watch mode
npx tsx watch src/​server.ts

# With Node.js flags
npx tsx --inspect src/​debug.ts

Package.json Scripts

{
  "scripts": {
    "dev": "tsx watch src/​index.ts",
    "start": "tsx src/​index.ts",
    "script": "tsx scripts/​migrate.ts"
  }
}

tsconfig.json for tsx

{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "bundler",
    "esModuleInterop": true
  }
}

TypeScript Compiler (tsc)

Build Only (No Bundling)

{
  "compilerOptions": {
    "outDir": "./​dist",
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true
  }
}
{
  "scripts": {
    "build": "tsc",
    "build:watch": "tsc --watch"
  }
}

Vite - Application Bundler

Installation

npm create vite@latest

Configuration

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/​plugin-react';

export default defineConfig({
  plugins: [react()],
  build: {
    target: 'ES2022',
    sourcemap: true,
    outDir: 'dist',
  },
  resolve: {
    alias: {
      '@': '/​src',
    },
  },
});

Library Mode

// vite.config.ts
import { defineConfig } from 'vite';
import { resolve } from 'node:path';

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, 'src/​index.ts'),
      name: 'MyLib',
      fileName: 'my-lib',
      formats: ['es', 'cjs'],
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
    },
  },
});

Build Scripts

Complete Build Pipeline

{
  "scripts": {
    "prebuild": "npm run clean",
    "build": "tsup",
    "postbuild": "npm run type-check",
    "clean": "rm -rf dist",
    "type-check": "tsc --noEmit"
  }
}

Watch Mode

{
  "scripts": {
    "dev": "tsup --watch",
    "dev:run": "tsx watch src/​index.ts"
  }
}

Output Formats

ESM (ES Modules)

// Output: dist/​index.js
export function hello() { }

CJS (CommonJS)

// Output: dist/​index.cjs
module.exports.hello = function() { }

Dual Package

// tsup.config.ts
export default defineConfig({
  format: ['esm', 'cjs'],
  dts: true,
});

Declaration Files

Generate .d.ts

// tsup.config.ts
export default defineConfig({
  dts: true, // Generate declaration files
});

Separate Declaration Build

{
  "scripts": {
    "build": "tsup && tsc --emitDeclarationOnly"
  }
}

Source Maps

// tsup.config.ts
export default defineConfig({
  sourcemap: true, // Generate source maps
});

Tree Shaking

// tsup.config.ts
export default defineConfig({
  treeshake: true, // Remove unused code
});

Minification

// tsup.config.ts
export default defineConfig({
  minify: true, // Minify output (production)
});

External Dependencies

// tsup.config.ts
export default defineConfig({
  external: ['react', 'react-dom'], // Don't bundle these
});

Best Practices Summary

  1. Use tsup for libraries - Simple, fast, handles dual packages
  2. Use tsx for scripts - Direct execution without build
  3. Use Vite for apps - Fast dev server, optimized builds
  4. Generate type declarations - Always include .d.ts files
  5. Support both ESM and CJS - Dual package format
  6. Enable source maps - For debugging
  7. Tree shake in production - Remove unused code

Code Review Checklist

  • Correct build tool selected for use case
  • tsup.config.ts or vite.config.ts present
  • Declaration files generated (dts: true)
  • Both ESM and CJS formats for libraries
  • Source maps enabled
  • External dependencies configured
  • Clean script removes old builds

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View