CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rollup-plugin-esbuild

A Rollup plugin that uses esbuild as a fast TypeScript/JavaScript compiler and minifier, replacing traditional tools like rollup-plugin-typescript2 and rollup-plugin-terser

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Rollup Plugin ESBuild

Rollup Plugin ESBuild is a high-performance Rollup plugin that leverages esbuild's fast TypeScript/JavaScript compilation and minification capabilities. It serves as a comprehensive replacement for multiple traditional Rollup plugins including rollup-plugin-typescript2, @rollup/plugin-typescript, and rollup-plugin-terser.

Package Information

  • Package Name: rollup-plugin-esbuild
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install rollup-plugin-esbuild esbuild --save-dev

Core Imports

import esbuild, { minify } from "rollup-plugin-esbuild";

For CommonJS:

const esbuild = require("rollup-plugin-esbuild").default;
const { minify } = require("rollup-plugin-esbuild");

Basic Usage

import esbuild from "rollup-plugin-esbuild";

export default {
  input: "src/index.ts",
  output: {
    file: "dist/bundle.js",
    format: "es",
  },
  plugins: [
    esbuild({
      include: /\.[jt]sx?$/,
      exclude: /node_modules/,
      sourceMap: true,
      minify: process.env.NODE_ENV === "production",
      target: "es2017",
      jsx: "transform",
      tsconfig: "tsconfig.json",
    }),
  ],
};

Architecture

Rollup Plugin ESBuild is built around several key components:

  • Main Plugin Function: The default export creates a full-featured Rollup plugin with transformation, compilation, and optional minification
  • Standalone Minify Plugin: The minify function provides minification-only functionality for projects that only need code compression
  • TypeScript Integration: Automatic tsconfig.json detection and configuration inheritance for seamless TypeScript compilation
  • Dependency Optimization: Experimental pre-bundling feature for optimizing external dependencies using esbuild's bundling capabilities
  • Flexible Loaders: Configurable file type processing with extensible loader system for different file formats

Capabilities

Main Plugin Function

Core esbuild transformation plugin providing TypeScript/JavaScript compilation, JSX transformation, and optional minification within the Rollup build pipeline.

function esbuild(options?: Options): RollupPlugin;

interface Options {
  include?: FilterPattern;
  exclude?: FilterPattern;
  sourceMap?: boolean;
  optimizeDeps?: OptimizeDepsOptions;
  tsconfig?: string | false;
  loaders?: { [ext: string]: Loader | false };
  // Plus all esbuild TransformOptions except 'sourcemap' and 'loader'
  minify?: boolean;
  minifyWhitespace?: boolean;
  minifyIdentifiers?: boolean;
  minifySyntax?: boolean;
  target?: string | string[];
  jsx?: "transform" | "preserve" | "automatic";
  jsxFactory?: string;
  jsxFragment?: string;
  jsxImportSource?: string;
  jsxDev?: boolean;
  define?: { [key: string]: string };
  charset?: "ascii" | "utf8";
  treeShaking?: boolean;
  ignoreAnnotations?: boolean;
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
  keepNames?: boolean;
  format?: "iife" | "cjs" | "esm";
  globalName?: string;
  mangleProps?: RegExp;
  reserveProps?: RegExp;
  mangleQuoted?: boolean;
  mangleCache?: { [key: string]: string | false };
  drop?: ("console" | "debugger")[];
  dropLabels?: string[];
}

type FilterPattern = string | RegExp | (string | RegExp)[];

Main Plugin

Standalone Minification

Standalone minification plugin for projects that only need code compression without transformation or compilation features.

function minify(options?: MinifyOptions): RollupPlugin;

interface MinifyOptions {
  sourceMap?: boolean;
  // Plus all esbuild TransformOptions except 'sourcemap'
  minify?: boolean;
  minifyWhitespace?: boolean;
  minifyIdentifiers?: boolean;
  minifySyntax?: boolean;
  target?: string | string[];
  charset?: "ascii" | "utf8";
  treeShaking?: boolean;
  ignoreAnnotations?: boolean;
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
  keepNames?: boolean;
  format?: "iife" | "cjs" | "esm";
  globalName?: string;
  mangleProps?: RegExp;
  reserveProps?: RegExp;
  mangleQuoted?: boolean;
  mangleCache?: { [key: string]: string | false };
  drop?: ("console" | "debugger")[];
  dropLabels?: string[];
}

Minification

Dependency Optimization

Experimental pre-bundling feature for optimizing external dependencies using esbuild's fast bundling capabilities, eliminating the need for additional CommonJS and Node.js resolution plugins.

interface OptimizeDepsOptions {
  include: string[];
  exclude?: string[];
  cwd: string;
  esbuildOptions?: EsbuildBuildOptions;
  sourceMap: boolean;
}

interface OptimizeDepsResult {
  optimized: Map<string, { file: string }>;
  cacheDir: string;
}

Dependency Optimization

Types

Core Types

// Re-export from esbuild for convenience
type Loader = 
  | "js" 
  | "jsx" 
  | "ts" 
  | "tsx" 
  | "css" 
  | "json" 
  | "text" 
  | "base64" 
  | "binary" 
  | "dataurl";

// Rollup plugin interface
interface RollupPlugin {
  name: string;
  options?: (opts: InputOptions) => InputOptions | null;
  buildStart?: (opts: NormalizedInputOptions) => void;
  resolveId?: (id: string, importer?: string) => string | null;
  transform?: (code: string, id: string) => TransformResult | null;
  renderChunk?: (code: string, chunk: RenderedChunk, options: NormalizedOutputOptions) => TransformResult | null;
}

interface TransformResult {
  code: string;
  map?: string | SourceMap | null;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rollup-plugin-esbuild@6.2.x
Publish Source
CLI
Badge
tessl/npm-rollup-plugin-esbuild badge