Files
stack/packages/mosaic/framework/skills/tsdown/references/option-minification.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

3.5 KiB

Minification

Compress code to reduce bundle size.

Overview

Minification removes unnecessary characters (whitespace, comments) and optimizes code for production, reducing bundle size and improving load times.

Note: Uses Oxc minifier internally. The minifier is currently in alpha.

Type

minify?: boolean | 'dce-only' | MinifyOptions
  • true — Enable full minification (whitespace removal, mangling, compression)
  • false — Disable minification (default)
  • 'dce-only' — Only perform dead code elimination without full minification
  • MinifyOptions — Pass detailed options to the Oxc minifier

Basic Usage

CLI

# Enable minification
tsdown --minify

# Disable minification
tsdown --no-minify

Note: The CLI --minify flag is a boolean toggle. For 'dce-only' mode or advanced options, use the config file.

Config File

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

DCE-Only Mode

Remove dead code without full minification (keeps readable output):

export default defineConfig({
  entry: ['src/index.ts'],
  minify: 'dce-only',
});

Example Output

Without Minification

// dist/index.mjs
const x = 1;

function hello(x$1) {
  console.log('Hello World');
  console.log(x$1);
}

hello(x);

With Minification

// dist/index.mjs
const e = 1;
function t(e) {
  (console.log(`Hello World`), console.log(e));
}
t(e);

Common Patterns

Production Build

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

Conditional Minification

export default defineConfig((options) => ({
  entry: ['src/index.ts'],
  format: ['esm'],
  minify: !options.watch, // Only minify in production
}));

Browser Library

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['iife'],
  platform: 'browser',
  globalName: 'MyLib',
  minify: true,
});

Multiple Builds

export default defineConfig([
  // Development build
  {
    entry: ['src/index.ts'],
    format: ['esm'],
    minify: false,
    outDir: 'dist/dev',
  },
  // Production build
  {
    entry: ['src/index.ts'],
    format: ['esm'],
    minify: true,
    outDir: 'dist/prod',
  },
]);

CLI Examples

# Production build with minification
tsdown --minify --clean

# Multiple formats with minification
tsdown --format esm --format cjs --minify

# Conditional minification (only when not watching)
tsdown --minify  # Or omit --watch

Tips

  1. Use minify: true for production builds
  2. Use 'dce-only' to remove dead code while keeping output readable
  3. Skip minification during development for faster rebuilds
  4. Combine with tree shaking for best results
  5. Test minified output thoroughly (Oxc minifier is in alpha)

Troubleshooting

Minified Code Has Bugs

Oxc minifier is in alpha and may have issues:

  1. Use DCE-only mode: minify: 'dce-only'
  2. Report bug to Oxc project
  3. Disable minification: minify: false

Unexpected Output

  • Test unminified first to isolate issue
  • Check source maps for debugging
  • Verify target compatibility