Skip to main content

Bundle

Creates and manages bundled JavaScript/TypeScript files using esbuild. Supports various output formats, sourcemaps, and platform targets.

Properties

string
required
Entry point for the bundle. Path to the source file to bundle (e.g., “src/handler.ts”).
string
Output directory for the bundle. Directory where the bundled file will be written.
string
Output filename for the bundle. Full path to the output file, overrides outdir if specified.
'iife' | 'cjs' | 'esm'
Bundle format:
  • iife: Immediately Invoked Function Expression
  • cjs: CommonJS
  • esm: ECMAScript Modules
string | string[]
Target environment. Examples: ‘node16’, ‘node18’, ‘es2020’
boolean
Whether to minify the output.
boolean | 'inline' | 'external' | 'both'
Whether to generate sourcemaps:
  • inline: Include sourcemap in bundle
  • external: Generate separate .map file
  • both: Generate both inline and external
string[]
External packages to exclude from bundle. Array of package names to mark as external.
'browser' | 'node' | 'neutral'
Platform to target:
  • browser: Browser environment
  • node: Node.js environment
  • neutral: Platform-agnostic

Returns

string
Path to the bundled file. Absolute or relative path to the generated bundle.
string
SHA-256 hash of the bundle contents. Used for cache busting and content verification.
string
The content of the bundle (the .js or .mjs file).

Examples

Bundle a TypeScript file for Node.js

Bundle for browser with minification

Bundle with external dependencies