elysia-hot-module-reload
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

elysia-hot-module-reload

An Elysia plugin that enables hot module reloading in the browser for local development!

Basic Usage With React

import Elysia from "elysia";
import { hotModuleReload, HotModuleReload } from "elysia-hot-module-reload";
import { renderToReadableStream } from "react-dom/server";

function App() {
  return <div>Hello world!</div>;
}

const app = new Elysia()
  .get("*", async (context) => {
    const stream = await renderToReadableStream(
      <>
        <App />
        <HotModuleReload />
      </>,
    );
    return new Response(stream, {
      headers: { "Content-Type": "text/html" },
    });
  })
  .use(hotModuleReload())
  .listen(3000);

console.info(
  `App is running at http://${app.server?.hostname}:${app.server?.port}`,
);

Custom Websocket Path

import Elysia from "elysia";
import { hotModuleReload, HotModuleReload } from "elysia-hot-module-reload";
import { renderToReadableStream } from "react-dom/server";

function App() {
  return <div>Hello world!</div>;
}

const customWebSocketPath = "my-custom-path";

const app = new Elysia()
  .get("*", async (context) => {
    const stream = await renderToReadableStream(
      <>
        <App />
        <HotModuleReload webSocketPath={customWebSocketPath} />
      </>,
    );
    return new Response(stream, {
      headers: { "Content-Type": "text/html" },
    });
  })
  .use(hotModuleReload({ webSocketPath: customWebSocketPath }))
  .listen(3000);

console.info(
  `App is running at http://${app.server?.hostname}:${app.server?.port}`,
);

Example usage with React + SSR!

Readme

Keywords

none

Package Sidebar

Install

npm i elysia-hot-module-reload

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.73 kB

Total Files

4

Last publish

Collaborators

  • dadajian