@lite-jsx/fastify
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Lite JSX - Fastify plugin

License Build Actions NPM Version NPM Downloads

Lite JSX is a lightweight JavaScript library that allows you to create and manipulate JSX elements using only vanilla JavaScript.


Installation

You can install Lite JSX via npm:

npm install @lite-jsx/core @lite-jsx/fastify

Using Lite JSX with Fastify

To use Lite JSX with Fastify, you can create a plugin that overrides the default reply.view function to add support for JSX templates. Here's an example:

const fastify = require("fastify")({ logger: true });
const { liteJsx } = require("@lite-jsx/fastify");

const { Home } = require("./home");

fastify.register(liteJsx);

fastify.get("/", (_request, reply) => {
  reply.view(Home, { message: "Hello world" });
});

fastify.listen({
  port: 3000,
});

To enable Lite JSX in our Fastify app, we're using the liteJsx plugin, which overrides the default reply.view function to add support for JSX templates.

This way, we can pass a JSX component to reply.view and it will be rendered as HTML.

And that's it! With these few lines of code, you can start using Lite JSX with Fastify to create powerful, dynamic web applications.


Contributing

If you'd like to contribute to Lite JSX, please feel free to submit a pull request or open an issue on GitHub:

https://github.com/lite-jsx/fastify

License

Lite JSX is licensed under the MIT License.

Package Sidebar

Install

npm i @lite-jsx/fastify

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

17.7 kB

Total Files

16

Last publish

Collaborators

  • danprates