lgarron / barely-a-dev-server

A teeny-tiny alternative to bundlers that does just what you need (and nothing more), using `esbuild`.
Other
6 stars 0 forks source link

barely-a-dev-server

A thin, opinionated wrapper for esbuild as a .ts web server. Given an entryRoot folder, it:

When run with "dev": false, it writes these files to an output dir (dist/ + the entry root by default), ready to serve using your favorite static file server.

Install with:

npm install -D barely-a-dev-server

Example

// script/build.js
import { barelyServe } from "barely-a-dev-server";

barelyServe({
  entryRoot: "src", // the only required arg
  dev: true,
  port: 3333,
  esbuildOptions: {
    target: "esnext",
  },
});

<!-- src/index.html -->
<script src="https://github.com/lgarron/barely-a-dev-server/raw/main/index.js" href="https://github.com/lgarron/barely-a-dev-server/blob/main/index.ts" type="module" defer></script>
// src/index.ts
const a: number = 4;
console.log(a);

(Note that src must reference the generated .js file, not .ts. The example shows an ergonomic hack: you can use href to store a reference to the .ts source, so that you can e.g. "Follow link" in VSCode.)

Why barely-a-dev-server?

Why not barely-a-dev-server?

These are mostly because it would make the codebase significantly larger to support them properly.