Convert Figma logo to code with AI

egoist logotsup

The simplest and fastest way to bundle your TypeScript libraries.

8,894
213
8,894
302

Top Related Projects

37,921

An extremely fast bundler for the web

9,097

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.

30,914

Rust-based platform for the Web

25,227

Next-generation ES module bundler

43,380

The zero configuration build tool for the web. 📦🚀

19,481

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️

Quick Overview

tsup is a zero-config TypeScript bundler powered by esbuild. It simplifies the process of bundling TypeScript projects by providing a streamlined, out-of-the-box solution with minimal configuration required.

Pros

  • Fast bundling thanks to esbuild integration
  • Supports multiple output formats (ESM, CJS, IIFE)
  • Automatic TypeScript declaration file generation
  • Built-in watch mode for development

Cons

  • Limited customization options compared to more complex bundlers
  • May not support all advanced TypeScript features
  • Dependency on esbuild, which is still in beta
  • Not suitable for complex bundling scenarios that require fine-grained control

Code Examples

  1. Basic usage:
// index.ts
export const greet = (name: string) => {
  console.log(`Hello, ${name}!`);
};
  1. Configuring output formats:
// tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  dts: true,
});
  1. Using CLI options:
tsup src/index.ts --format esm,cjs --dts

Getting Started

  1. Install tsup:
npm install tsup --save-dev
  1. Add a script to your package.json:
{
  "scripts": {
    "build": "tsup src/index.ts --format cjs,esm --dts"
  }
}
  1. Run the build:
npm run build

This will generate CommonJS and ES Module outputs along with TypeScript declaration files.

Competitor Comparisons

37,921

An extremely fast bundler for the web

Pros of esbuild

  • Extremely fast build times due to its Go-based implementation
  • Supports a wide range of file formats and transformations out of the box
  • Highly configurable with a rich API for advanced use cases

Cons of esbuild

  • Steeper learning curve for complex configurations
  • Less opinionated, requiring more setup for common use cases
  • Limited built-in TypeScript type checking (requires separate step)

Code Comparison

esbuild:

require('esbuild').build({
  entryPoints: ['app.js'],
  bundle: true,
  outfile: 'out.js',
}).catch(() => process.exit(1))

tsup:

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  dts: true,
})

Key Differences

  • tsup is built on top of esbuild, providing a more opinionated and user-friendly interface
  • tsup offers better out-of-the-box TypeScript support, including automatic declaration file generation
  • esbuild provides more granular control over the build process, while tsup focuses on simplicity for common use cases

Both tools are excellent choices for bundling JavaScript and TypeScript projects, with esbuild offering raw performance and flexibility, and tsup providing a more streamlined experience for typical scenarios.

9,097

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.

Pros of ncc

  • Simpler setup and usage, requiring minimal configuration
  • Produces a single output file, ideal for serverless deployments
  • Better support for Node.js-specific features and modules

Cons of ncc

  • Limited customization options compared to tsup
  • Slower build times for larger projects
  • Less active development and community support

Code Comparison

ncc:

ncc build input.js -o dist

tsup:

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  dts: true,
})

Key Differences

  • tsup offers more flexibility in output formats (CJS, ESM, IIFE)
  • ncc focuses on bundling for Node.js, while tsup supports both browser and Node.js environments
  • tsup provides built-in TypeScript support and generates declaration files
  • ncc excels in creating single-file outputs, while tsup allows for multiple entry points and outputs

Use Cases

  • Choose ncc for simple Node.js projects or serverless functions
  • Opt for tsup when building libraries or applications with complex bundling requirements

Both tools have their strengths, and the choice depends on your project's specific needs and target environment.

30,914

Rust-based platform for the Web

Pros of SWC

  • Significantly faster compilation speeds due to being written in Rust
  • More comprehensive feature set, including support for JSX, TypeScript, and minification
  • Highly configurable with a wide range of options for customization

Cons of SWC

  • Steeper learning curve and more complex setup compared to tsup
  • Less focused on TypeScript-specific use cases
  • May require more configuration for simple projects

Code Comparison

SWC configuration example:

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2015"
  }
}

tsup configuration example:

export default {
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  dts: true,
}

Summary

SWC is a more powerful and versatile tool, offering faster compilation and a broader range of features. However, it comes with increased complexity and a steeper learning curve. tsup, on the other hand, provides a simpler, more focused solution for TypeScript projects, with an emphasis on ease of use and quick setup. The choice between the two depends on project requirements, team expertise, and the desired balance between performance and simplicity.

25,227

Next-generation ES module bundler

Pros of Rollup

  • More mature and widely adopted in the JavaScript ecosystem
  • Highly extensible with a rich plugin ecosystem
  • Supports code splitting and dynamic imports out of the box

Cons of Rollup

  • Steeper learning curve, especially for complex configurations
  • Slower build times for larger projects compared to tsup
  • Requires more manual configuration for TypeScript projects

Code Comparison

Rollup configuration:

// rollup.config.js
export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  }
};

tsup configuration:

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

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

Summary

Rollup is a more established and flexible bundler with extensive plugin support, making it suitable for complex projects. However, it can be more challenging to set up and slower for large codebases. tsup, on the other hand, offers a simpler configuration and faster build times, especially for TypeScript projects, but may lack some advanced features and customization options available in Rollup.

43,380

The zero configuration build tool for the web. 📦🚀

Pros of Parcel

  • Zero configuration out of the box, making it easier for beginners
  • Supports a wide range of file types and assets without additional plugins
  • Faster build times due to multicore processing and caching

Cons of Parcel

  • Less flexible for advanced configurations compared to tsup
  • Larger bundle sizes in some cases
  • Can be overkill for simple projects or libraries

Code Comparison

Parcel:

// No configuration needed, just run:
parcel index.html

tsup:

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

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  dts: true,
})

Summary

Parcel is a zero-configuration bundler that's great for quick starts and diverse projects. It handles various file types out of the box and offers fast build times. However, it may produce larger bundles and can be less flexible for advanced use cases.

tsup, on the other hand, is more focused on TypeScript and JavaScript projects. It requires some configuration but offers more control over the build process. tsup is lighter and more suitable for library development, while Parcel excels in diverse web application bundling scenarios.

Choose Parcel for rapid development and ease of use, especially in complex web applications. Opt for tsup when building libraries or when you need more control over your TypeScript/JavaScript bundling process.

19,481

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️

Pros of Snowpack

  • Offers a faster development experience with instant updates
  • Provides a more modern, ESM-based build approach
  • Supports a wide range of file types and frameworks out of the box

Cons of Snowpack

  • May require additional configuration for complex projects
  • Has a steeper learning curve for developers used to traditional bundlers
  • Can result in larger file sizes in production builds without optimization

Code Comparison

Snowpack configuration:

// snowpack.config.js
module.exports = {
  mount: {
    public: '/',
    src: '/dist',
  },
  plugins: ['@snowpack/plugin-react-refresh'],
};

tsup configuration:

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

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

While Snowpack focuses on providing a modern development experience with ESM-based builds, tsup is more specialized in bundling TypeScript projects with minimal configuration. Snowpack offers a broader range of features and supports various file types, making it suitable for complex web applications. On the other hand, tsup excels in simplicity and ease of use, particularly for TypeScript libraries and smaller projects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

tsup

npm version npm downloads

Bundle your TypeScript library with no config, powered by esbuild.

👀 What can it bundle?

Anything that's supported by Node.js natively, namely .js, .json, .mjs. And TypeScript .ts, .tsx. CSS support is experimental.

⚙️ Install

Install it locally in your project folder:

npm i tsup -D
# Or Yarn
yarn add tsup --dev
# Or pnpm
pnpm add tsup -D

You can also install it globally but it's not recommended.

📖 Usage

Bundle files

tsup [...files]

Files are written into ./dist.

You can bundle multiple files in one go:

tsup src/index.ts src/cli.ts

This will output dist/index.js and dist/cli.js.

📚 Documentation

For complete usages, please dive into the docs.

For all configuration options, please see the API docs.

💬 Discussions

Head over to the discussions to share your ideas.

Sponsors

Ship UIs faster with automated workflows for Storybook

sponsors

Project Stats

Alt

License

MIT © EGOIST

NPM DownloadsLast 30 Days