On-demand runtime webpack compilations over HTTP.

Overview

webpack-http-server

On-demand runtime webpack compilations over HTTP.

Overview

This package is, effectively, an Express server that exposes webpack compilations over HTTP. This means you can request to compile a module on runtime by dispatching a request like this:

POST http://127.0.0.1:8080/compilation
Content-Type: application/json

{"entry":"/Users/you/some/module.js"}

The server will respond you with the compilation info:

{
  "id": "COMPILATION_ID",
  "previewUrl": "http://127.0.0.1/compilation/"
}

Each compilation request creates a unique compilation ID and /compilations/:id route to preview the runtime of the given module after it's compiled.

Motivation

I've build this library because I'm a fan of example-driven testing. When I employ it on bigger projects, it means that every test I have has a runtime usage example alongside it. While I could compile those examples before tests, I chose to have a runtime compilation server instead. Here are my reasons:

  1. Compilation server guarantees up-to-date examples. I may forget to run npm run build:examples before running tests, which will yield irrelevant test results.
  2. Compilation server is more performant. By using the server and compiling only those examples that my current test run needs, I can save resources by skipping irrelevant examples.
  3. Compilation server creates a runtime. Even if I build examples before tests, I still need something to serve them. This server does that as well via compilation previews.

Why not webpack-dev-server?

Webpack Dev Server is a great tool to run your compilation over HTTP. However, it's scoped to a single compilation. You cannot change the entrypoint for your dev server without having to stop it, modify the webpack config, and re-run the server. This is extremely time consuming and unreliable.

Getting started

Install

npm install webpack-http-server

Create a server

import { WebpackHttpServer } from 'webpack-http-server'

const server = new WebpackHttpServer()
await server.listen()

console.log('Compilation server listening at "%s"', server.serverUrl)

The compilation server runs on a random vacant port. Rely on the serverUrl property to get its full address.

Request a compilation

There are two ways to request a compilation: HTTP request and Node.js API.

HTTP request

fetch(`${server.serverUrl}/compilation`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    entry: '/Users/octocat/projects/demo/index.js',
  }),
})

Node.js API

const result = await server.compile(['/Users/octocat/projects/demo/index.js'])
console.log('preview is running on "%s"', result.previewUrl)
You might also like...

This an CRUD app built were users can create, update and delete specific day to day tasks as they wish. The app is built using webpack and served with webpack dev server

This an CRUD app built were users can create, update and delete specific day to day tasks as they wish. The app is built using webpack and served with webpack dev server

Todo-List This an CRUD app built were users can create, update and delete specific day to day tasks as they wish. The app is built using webpack and s

Sep 28, 2022

io-ts Typed Event Bus for the runtime of your Node.js application. A core for any event-driven architecture based app.

Typed Event Bus Based on io-ts types, this bus provides a handy interface to publish and consume events in the current runtime of the Node.js process.

May 23, 2022

Runtime object parsing and validation with static TypeScript typing.

TypeParse Runtime object transformation, parsing and validation with inferred static TypeScript typing. Install Using npm npm install typeparse Using

May 5, 2022

Simple, lightweight at-runtime type checking functions, with full TypeScript support

pheno Simple, lightweight at-runtime type checking functions, with full TypeScript support Features Full TypeScript integration: TypeScript understand

Sep 5, 2022

Cross-runtime JavaScript framework

Primate, a cross-runtime framework Primate is a full-stack cross-runtime Javascript framework (Node.js and Deno). It relieves you of dealing with repe

Nov 7, 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

🦆 lightning fast duckdb bindings for bun runtime

@evan/duckdb lightning fast duckdb bindings for bun runtime Install bun add @evan/duckdb Features 🔋 batteries included 🚀 jit optimized bindings 🐇 4

Oct 20, 2022

Cross-runtime benchmarking lib and cli

Cross-runtime benchmarking lib and cli

mitata cross-runtime benchmarking lib Install bun add mitata npm install mitata Examples import { run, bench, group, baseline } from 'mitata'; // den

Jan 3, 2023

Example code for MFE routing, shared state, build-time & runtime deploy video

Turborepo starter with pnpm This is an official starter turborepo. What's inside? This turborepo uses pnpm as a packages manager. It includes the foll

Nov 2, 2022
Releases(v0.3.0)
Owner
Artem Zakharchenko
Teaching people that testing can be useful and fun.
Artem Zakharchenko
An on-demand peer tutoring platform by students, for students.

OURFinals An on-demand peer tutoring platform by students, for students. Database The prisma/ folder contains: migrations/: Past database migrations (

Aditya Banerjee 3 Jan 6, 2022
This project is a Web application based on an external API. The API provides data about music (including artists, albums, etc) that users can access on-demand. This project was built with ES6, HTML and CSS and it is a SPA.

Capstone M2: Music App This project is a Web application based on the music API Napster built with ES6, HTML and CSS and it is a SPA. This API provide

Karla Delgado 12 Aug 29, 2022
Motionia is a lightweight simplified on demand animation library

The Ultimate & smart JS animation library! Simple fast , flexible & easy to integrate. No need to write page long CSS Keyframes that consumes a lot of

Abhi 324 Dec 30, 2022
📡Usagi-http-interaction: A library for interacting with Http Interaction API

?? - A library for interacting with Http Interaction API (API for receiving interactions.)

Rabbit House Corp 3 Oct 24, 2022
This is a simple web app that allows a user add list of tasks that needs to be completed. It is built using webpack and served by a webpack dev server.

TO-DO-LIST "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as compl

Favour Ezeugwa 18 Aug 19, 2022
A simple HTML page maintaining list of To Do tasks using webpack and served by a webpack dev server.

Task Organiser In this project, we build a simple HTML list of To Do tasks using webpack and served by a webpack dev server. Built With HTML CSS Javas

Angom 4 Jun 24, 2022
This project is about building a simple HTML list of To Do tasks. Built using webpack and served by a webpack dev server.

To Do List app This project is about building a simple HTML list of To Do tasks and is built using webpack and served by a webpack dev server. Built W

Dino Ronald Quispe Arias 6 Nov 4, 2022
In this project, we built a simple HTML list of To Do tasks. This simple web page was created using webpack and served by a webpack dev server.

To do list In this project, we built a simple HTML list of To Do tasks. This simple web page was created using webpack and served by a webpack dev ser

Jesús Vázquez 8 Dec 21, 2022
In this project, I build a simple HTML list of To Do tasks. This simple web page will be built using webpack and served by a webpack dev server.

To Do list with Webpack In this project, I build a simple HTML list of To Do tasks. This simple web page will be built using webpack and served by a w

Sidney Kaguli 8 Aug 23, 2022
In this project, I built a simple HTML list of To Do tasks. The list is styled according to the specifications listed later in this lesson. This simple web page is built using webpack and served by a webpack dev server.

Awesome books:JavaScript Using Modules In this project, I built a simple HTML list of To Do tasks. The list is styled according to the specifications

 Hassan Momanyi 10 Nov 25, 2022