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

Overview

esbuild-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 --save-dev esbuild esbuild-server

Usage

Create a new file for your dev server:

// dev-server.js
require('esbuild-server')
  .createServer(
    {
      bundle: true,
      entryPoints: ['src/app.js'],
    },
    {
      static: 'public',
    }
  )
  .start();

Assuming you have an index.html file in the public folder you can now run the server with node dev-server.js.

See example folder for examples.

API

createServer(esbuildOptions, serverOptions)

esbuildOptions

Options passed to esbuild Build API. If not specified watch defaults to true to enable continous build and live reload, and similarly if no type of output option is specified outdir is set to a temporary directory.

serverOptions

Option Description Default
static Path to your static assets folder, should contain an index.html file. None
port Port number to listen for requests on. 8080
historyApiFallback For Single Page Apps using the HTML5 History API, the index.html page is served instead of 404 responses. false
injectLiveReload Inject snippet to automatically reload the page when file changes are detected. true
open Open the browser after server had been started. Set to a string to open a particular path. false
proxy Proxy certain paths to a separate API backend when you want to serve API requests on the same domain. Pass a function for dynamic rewrites. {}
onProxyRewrite Callback function when a proxy rewrite happens, useful for logging or altering the response. None

Proxying

Static

{
  proxy: {
    '/api': 'http://localhost:3000'
  }
}

A request to /api/users will now proxy the request to http://localhost:3000/api/users. If you want to rewrite the base use dynamic approach instead:

Dynamic

{
  proxy: (path) => {
    if (path.startsWith('/api')) {
      return path.replace(/^\/api/, 'http://localhost:3000');
    }
  };
}

A request to /api/users will now proxy the request to http://localhost:3000/users.

Modifying the response

{
  onProxyRewrite: (proxyRes, localUrl, proxyUrl) => {
    console.log(`Proxying ${localUrl} to ${proxyUrl}`);
    proxyRes.headers['x-my-custom-header'] = 'yep';
    return proxyRes;
  };
}

Live reload

If you want more control over where the live reload script is injected you can place it manually with:

<script src="/esbuild-livereload.js" async></script>

License

MIT © Joel Arvidsson 2022 – present

You might also like...

A Node.js framework for development of fast, simple, lightweight website.

MiuJS Web Framework A simple and minimal web framework using the JavaScript and Node.js. Featuring: builtin server multiple deploy target node vercel

Jun 19, 2022

A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

remote-map-cache A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fa

Oct 31, 2022

The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

介绍 项目集成了工作流引擎、报表引擎和组织机构权限管理后台,可以应用于OA、HR、CRM、PM等系统开发。配合使用tlv8 ide可以快速实现业务系统开发、测试、部署。 后台采用Spring MVC架构简单方便,前端使用流行的layui界面美观大方。 采用组件开发技术,提高系统的灵活性和可扩展性;采

Dec 27, 2022

Password Generator - A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords

A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords. Password Generator is free to use as a secure password generator on any computer, phone, or tablet.

Aug 3, 2022

front-end framework for fast and powerful configuration of utilities and intuitive UI

front-end framework for fast and powerful configuration of utilities and intuitive UI Getting Started with Vector → Getting started A variety of optio

Jun 29, 2022

front-end framework for fast and powerful configuration of utilities and intuitive UI

front-end framework for fast and powerful configuration of utilities and intuitive UI Getting Started with Vector → Getting started A variety of optio

Jun 29, 2022

Monolithic repo for api server, image server, web server

Onsecondary Market Deployed at https://market.onsecondary.com Monolithic repo for api server, image server, web server TODO -use a script to cull expi

Jan 11, 2022

Dynamic-web-development - Dynamic web development used CSS and HTML

Dynamic-web-development - Dynamic web development used CSS and HTML

Dynamic-web-development ASSISNMENT I just used CSS and HTML to make a mobile int

Feb 8, 2022

⚗️Nitro provides a powerful toolchain and a runtime framework from the UnJS ecosystem to build and deploy any JavaScript server, anywhere

⚗️Nitro provides a powerful toolchain and a runtime framework from the UnJS ecosystem to build and deploy any JavaScript server, anywhere

Jan 5, 2023
Comments
  • Error for requests with extensions not covered by mime.ts

    Error for requests with extensions not covered by mime.ts

    When I manually send a request in my browser or using curl to /favicon.ico, I get the following error:

    node:internal/errors:477
        ErrorCaptureStackTrace(err);
        ^
    
    TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Type"
        at storeHeader (node:_http_outgoing:532:5)
        at processHeader (node:_http_outgoing:527:3)
        at ServerResponse._storeHeader (node:_http_outgoing:421:11)
        at ServerResponse.writeHead (node:_http_server:370:8)
        at sendFile (/home/dara/git/OverDB/packages/frontend/node_modules/esbuild-server/dist/index.js:126:17)
        at async Server.<anonymous> (/home/dara/git/OverDB/packages/frontend/node_modules/esbuild-server/dist/index.js:178:28) {
      code: 'ERR_HTTP_INVALID_HEADER_VALUE'
    }
    

    This is due to the file extension (.ico) not being specified in mime.ts, and an undefined value being passed into res.writeHead.

    If you're accepting PRs, I can make a fix that doesn't set Content-Type if it can't be determined. Another change I'd like to make is using the robust mime library for determining mime type for a much larger number of file extensions (including .ico).

    opened by daradermody 0
  • Fallback to reading the entire file when filehandle.createReadStream() isn't available

    Fallback to reading the entire file when filehandle.createReadStream() isn't available

    filehandle.createReadStream has only been available since NodeJS v16.11.0. Users not yet on a version this recent will be prevented from using this package due to us not gracefully falling back to another implementation.

    See: https://github.com/oblador/esbuild-server/blob/c26201077fbcb6800ae8dc82229dd8470a5d782a/src/index.ts#L188-L189

    opened by cuongvo 4
Releases(v0.1.2)
Owner
Joel Arvidsson
╥━━━━━━━━╭━━╮━━┳ ╢╭╮╭━━━━━┫┃▋▋━▅┣ ╢┃╰┫┈┈┈┈┈┃┃┈┈╰┫┣ ╢╰━┫┈┈┈┈┈╰╯╰┳━╯┣ ╢┊┊┃┏┳┳━━┓┏┳┫┊┊┣ ╨━━┗┛┗┛━━┗┛┗┛━━┻
Joel Arvidsson
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Lightweight and versatile build tool based on the esbuild compiler

Estrella is a lightweight and versatile build tool based on the fantastic esbuild TypeScript and JavaScript compiler. Rebuild automatically when sourc

Rasmus 1.1k Jan 2, 2023
A fast and powerful http toolkit that take a list of domains to find active domains and other information such as status-code, title, response-time , server, content-type and many other

HTTPFY curently in beta so you may see problems. Please open a Issue on GitHub and report them! A Incredible fast and Powerful HTTP toolkit Report Bug

DevXprite 44 Dec 22, 2022
🚀 Using top-level await in AWS Lambda with TypeScript, esbuild and Serverless Framework

?? Top-level await in AWS Lamba with TypeScript Articles https://dev.to/oieduardorabelo/top-level-await-in-aws-lamba-with-typescript-1bf0 https://medi

Eduardo Rabelo 17 Nov 23, 2022
esbuild plugin to generate mix-manifest.json file compatible with Laravel Mix.

esbuild-mix-manifest-plugin An esbuild plugin to generate a mix-manifest.json compatible with Laravel Mix. Installation You can install the plugin via

Stefan Zweifel 6 Dec 25, 2022
This is a library that makes it possible to change the configuration values of the Remix compiler (esbuild).

?? remix-esbuild-override ⚠️ While I believe you will most likely get a lot of benefit from using this library, it can sometimes destroy your product.

AijiUejima 73 Dec 22, 2022
An esbuild plugin to inject your application's version number or today's date into your files

esbuild-plugin-version-injector An esbuild plugin to inject your application's version number or today's date into your files This plugin was inspired

Favware 6 Dec 6, 2022
An esbuild plugin for simplifying global API calls.

esbuild-plugin-global-api This plugin is still experimental, not recommended for production. It may break your code in some cases. An esbuild plugin f

null 4 Nov 15, 2022
A-Frame Element is a simple library for building fast, lightweight web components for 3D development

aframe-element is a library inspired from the very nice library Polymer lit to map A-Frame AR / VR / 3D elements on typescript classes like Angular/React/Lit.

null 6 May 31, 2022