0.135.1 • Published 5 months ago
esm.sh v0.135.1
esm.sh
The esm.sh CLI/API for serving hot applications.
Using the CLI tool
The CLI tool is used to run a hot application in current directory.
npx esm.sh -w
The
-w
option is for watching the file changes to enable HMR.
Using the API
The esm.sh API uses standard web APIs to serve hot applications.
export interface ServeOptions {
/** The root path, default to current working directory. */
root?: string;
/** The fallback route, default is `index.html`. */
fallback?: string;
}
export function serveHost(
options?: ServeOptions,
): (req: Request) => Promise<Response>;
For Node.js runtime, you need @hono/server
to listen to the requests.
import { serve } from "@hono/server";
import { serveHot } from "esm.sh";
serve({ port: 3000, fetch: serveHot() });
For Deno runtime, you can use serveHot
directly.
import { serveHot } from "https://esm.sh";
Deno.server(serveHot());
For Bun runtime:
import { serveHot } from "esm.sh";
Bun.serve({ port: 3000, fetch: serveHot() });