@zhourengui/esbuild-dev-server
TypeScript icon, indicating that this package has built-in type declarations

1.0.16 • Public • Published

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

Package Sidebar

Install

npm i @zhourengui/esbuild-dev-server

Weekly Downloads

1

Version

1.0.16

License

MIT

Unpacked Size

7.87 kB

Total Files

6

Last publish

Collaborators

  • zhourengui