@vitemin/fastify-plugin
v1.0.1
Published
Plugin to run fastify inside vite
Downloads
6
Readme
Vite Fastify Plugin
This plugin helps you to run fastify server along with vite dev server.
Installation
npm
npm i @vitemin/fastify-plugin -Dpnpm
pnpm add @vitemin/fastify-plugin -Dyarn
yarn add @vitemin/fastify-plugin -DUsage
In order to use this plugin you need to export instance from fastify server
app.ts / app.js
import fastify from 'fastify';
export const app = fastify();
/**
* your app code here
*/[!NOTE]
You need run your server in a separate file. You can run the server in the file in the same file where you instantiate fastify but this will occupy additional port.
vite.config.js / vite.config.ts
import viteReact from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { app } from './server/app';
import { fastifyDevServerPlugin } from '@vitemin/fastify-plugin';
export default defineConfig({
plugins: [
viteReact(),
fastifyDevServerPlugin(app, { prefix: '/api' }),
]
});
