Skip to content

Fast, lightweight and powerful development server for esbuild

Notifications You must be signed in to change notification settings

zhourengui/esbuild-dev-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esbuild-dev-server

⚡️ Fast, lightweight and powerful development server for esbuild ⚡️

  • Zero dependencies besides esbuild
  • API proxy support
  • Live reload
  • SPA support through History API fallback
  • Fully typed with TypeScript

Installation

npm install @zhourengui/esbuild-dev-server
# or
yarn add @zhourengui/esbuild-dev-server

Usage

import { createDevServer } from '@zhourengui/esbuild-dev-server';

createDevServer(esbuildOptions, {
  servedir: 'dist/web',
  port: 8080,
  proxy: {
    '^/api/v1': {
      target: 'https://www.google.com/',
      changeOrigin: true,
    },
  },
});

See example folder for examples.

API

createDevServer(esbuildOptions, serverOptions)

esbuildOptions

Options passed to esbuild Build API.

serverOptions

Option Description Required Default
servedir build directory True None
port Port number to listen for requests on. True None
open Open in the default browser after starting the service False False
proxy proxy http network request False None

Proxying

{
  "proxy": {
    "^/api/v1": {
      "target": "https://www.google.com.hk/",
      "pathRewrite": {
        "^/api/v1": "replace string"
      },
      "changeOrigin": true
    }
  }
}

Matching prefixes support regular expressions.

Hot Reloading

Add the following code to the entry file:

// Hot Module
if (process.env.NODE_ENV === 'development') {
  import('@zhourengui/esbuild-dev-server/lib/hot-reloading');
}

Todo List

  • Add Tests

About

Fast, lightweight and powerful development server for esbuild

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published