Skip to content
GitHubXDiscordRSS

Bundle

Learn how to use Alchemy's esbuild provider to bundle JavaScript and TypeScript code for your serverless functions and web applications.

The Bundle resource uses esbuild to bundle JavaScript and TypeScript files into optimized output.

Bundle a TypeScript file into ESM format:

import { Bundle } from "alchemy/esbuild";
const bundle = await Bundle("handler", {
entryPoint: "src/handler.ts",
format: "esm",
});

Specify an output directory and additional build options:

const bundle = await Bundle("api", {
entryPoint: "src/api.ts",
outdir: ".build",
format: "esm",
platform: "node",
target: "node18",
minify: true,
sourcemap: true,
});

Exclude packages from the bundle:

const bundle = await Bundle("app", {
entryPoint: "src/app.ts",
format: "esm",
external: ["aws-sdk", "lodash"],
platform: "node",
});

Create a browser-compatible IIFE bundle:

const bundle = await Bundle("web", {
entryPoint: "src/main.ts",
outfile: "dist/bundle.js",
format: "iife",
platform: "browser",
minify: true,
sourcemap: "external",
});