barely-a-dev-server
A thin, opinionated wrapper for esbuild
as a .ts
web server. Given an entryRoot
folder, it:
.ts
files under entryRoot
and uses them as entry files to run esbuild
in watch
mode, and.js
files together with a fallback to entryRoot
for static files.
/
are mapped to index.html
in the corresponding folder.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
// 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.)
barely-a-dev-server
?esbuild
, which is very fast and robust.
esbuild
.barely-a-dev-server
?esbuild
's --servedir
arg during dev, and cp -R
for a build.node -e 'import("barely-a-dev-server").then(s => s.barelyServe({entryRoot: "src"}))'
.ts
file under the entryRoot
as an entry point. esbuild
handles this very well, but this may result in significantly more output files than expected/needed.
These are mostly because it would make the codebase significantly larger to support them properly.