esbuild-server

0.3.0 · active · verified Sun Apr 19

esbuild-server is a development server specifically designed to integrate with esbuild for rapid, lightweight asset bundling and serving. It features zero runtime dependencies beyond esbuild itself, providing live reload, API proxying with dynamic rewrite capabilities, SPA support via History API fallback, and static asset serving. The current stable version is `0.3.0`, with a release cadence that addresses bug fixes and introduces new features like HTTPS support. It differentiates itself by tightly coupling with esbuild's build process, offering a minimal setup, and being fully typed for TypeScript environments, making it an efficient choice for projects already leveraging esbuild.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `esbuild-server` with TypeScript, bundling `src/app.ts` into a `dist` directory, serving static files from `public`, enabling live reload, history API fallback, and an example API proxy. It also shows how to define environment variables.

import { createServer } from 'esbuild-server';
import path from 'path';

const rootDir = process.cwd();

createServer(
  {
    bundle: true,
    entryPoints: [path.join(rootDir, 'src/app.ts')],
    outdir: path.join(rootDir, 'dist'),
    // Example: process.env.NODE_ENV !== 'production' ? 'development' : 'production'
    define: { 'process.env.NODE_ENV': JSON.stringify('development') }
  },
  {
    static: path.join(rootDir, 'public'), // Assumes 'public' directory with 'index.html'
    port: 8080,
    historyApiFallback: true, // Useful for SPAs
    injectLiveReload: true,
    open: true, // Opens browser automatically
    proxy: {
      '/api': 'http://localhost:3001' // Example API proxy
    },
    // https: {
    //   key: fs.readFileSync('server.key'),
    //   cert: fs.readFileSync('server.crt'),
    // }
  }
).start();

console.log('esbuild-server started on http://localhost:8080');

view raw JSON →