In the world of web development, speed is everything. We chase faster load times, quicker API responses, and more responsive user interfaces. Yet, one of the most significant bottlenecks in our daily workflow often goes unoptimized: the build process. Slow npm install commands and complex bundler configurations in our CI/CD pipelines can add minutes of dead time to every single deployment, killing productivity and slowing down feedback loops.
While tools like esbuild have emerged, promising near-instant builds thanks to their Go-based architecture, integrating them efficiently isn't always straightforward. You still have to manage Node.js versions, npm dependencies, and caching strategies within your CI environment.
But what if you could access the raw power of esbuild without any of that overhead? What if bundling your assets was as simple as making an API call?
This is the promise of esbuild.do, an agentic workflow platform that provides esbuild as a service. In this guide, we'll show you how to integrate this powerful API into your CI/CD pipeline to slash build times and simplify your entire deployment process.
Before diving into the solution, let's look at the problem. A typical CI/CD job for a frontend application might look like this:
The build tool itself might be fast, but the surrounding setup—installing dependencies, warming up caches—adds significant overhead. Every minute spent here is a minute developers are waiting for a deployment to finish. This is where a "build tool as a service" model shines.
esbuild.do provides esbuild's core functionality through a simple, scalable API. Instead of installing and configuring the esbuild binary in your pipeline, you simply send your source code to the API and receive the bundled, minified output in milliseconds.
This approach offers several immediate advantages for any CI/CD workflow:
Let's get practical. Integrating esbuild.do is incredibly simple using the @do-business/sdk. Imagine you have a small TypeScript project with two files:
src/index.ts:
import { greet } from './utils';
console.log(greet("World from our CI Pipeline"));
src/utils.ts:
export const greet = (name: string): string => `Hello, ${name}!`;
To bundle this in a CI job, you'd create a simple Node.js script (e.g., build.js).
Step 1: Install the SDK
You only need one lightweight dependency in your package.json:
npm install @do-business/sdk
Step 2: Create a Build Script
This script will read your source files, send them to the esbuild.do agent, and save the result.
build.js:
import { Agent } from '@do-business/sdk';
import fs from 'fs/promises';
import path from 'path';
// Initialize the esbuild.do agent
const esbuild = new Agent('esbuild.do');
// Define project source files
const projectFiles = ['src/index.ts', 'src/utils.ts'];
async function build() {
console.log('Reading source files...');
// Create the 'sources' object for the API
const sources = {};
for (const file of projectFiles) {
// Use the relative path as the key in the virtual filesystem
sources[file] = await fs.readFile(path.resolve(file), 'utf-8');
}
console.log('Sending bundle request to esbuild.do...');
// Call the bundle method
const { code, map } = await esbuild.bundle({
entryPoints: ['src/index.ts'], // Your main entry point
sources: sources, // The virtual filesystem
bundle: true,
minify: true,
platform: 'node',
target: 'es2020',
sourcemap: true,
});
console.log('Bundle received! Writing to dist/ folder...');
// Create output directory and write the bundled files
await fs.mkdir('dist', { recursive: true });
await fs.writeFile('dist/bundle.js', code);
await fs.writeFile('dist/bundle.js.map', map);
console.log('--- Build complete! ---');
console.log('Output written to dist/bundle.js');
}
build().catch(err => {
console.error('Build failed:', err);
process.exit(1);
});
Step 3: Run it in Your CI Pipeline
Now, your CI job simplifies dramatically. Here’s a conceptual github-action.yml:
name: Build and Deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm' # Caches only the tiny SDK, not a huge toolchain
- name: Install SDK
run: npm install
- name: Run API-based Build
run: node build.js # This executes our script
# ... next steps to deploy the 'dist' folder
You've just replaced a potentially heavy build step with a lightweight, blazing-fast API call. Your npm install will be seconds, not minutes, and the build itself is offloaded to a highly optimized service.
Here are some common questions about using esbuild.do.
What is esbuild.do?
esbuild.do provides esbuild's powerful bundling, transpilation, and minification capabilities as a simple and robust API. It allows you to integrate a high-speed build step into any application or workflow without installing or configuring local build tools.
Why use an API for esbuild instead of the CLI?
Using esbuild.do abstracts away the complexity of managing binary dependencies, versions, and build environments. It's perfect for serverless functions, CI/CD pipelines, online playgrounds, and any environment where installing Node.js and npm packages is inconvenient.
What languages and formats does esbuild.do support?
Just like the underlying tool, our agent supports JavaScript (JS, JSX) and TypeScript (TS, TSX). It can also bundle CSS, load JSON files, and handle various output formats like IIFE, CommonJS (CJS), and ES Modules (ESM).
How does source data work with the bundle method?
You provide an object where keys are filenames and values are the file content as strings. Our agent creates a virtual file system to process these, resolves imports between them, and returns the final bundled code.
Slow builds are more than just an inconvenience; they are a drag on innovation. By shifting from a local toolchain to an API-first approach with esbuild.do, you can simplify your infrastructure, accelerate your deployments, and give your developers their most valuable resource back: time.
Ready to see the difference for yourself? Get started at esbuild.do and transform your build pipeline today.