Enhance your Fastify DX with the power of Vite & Vitest.
- ⚡ All the power of Vite (Next Generation
FrontendIsomorphic Tooling):- Lightning fast HMR (hot module replacement) in dev mode with Vite Plugin Node.
- Smart & instant watch mode, like HMR for tests with Vitest.
- 🛠️ DX setup:
- Vite, Prettier and Typescript with common config, esnext ready and alias
@/* - Tests with one Fastify instance setup, code coverage
- Fastify with logger
- Production build without Vite
- Vite, Prettier and Typescript with common config, esnext ready and alias
So, it's super fast donc ça va super vite 🚀
See Why and How Vite in node and Why Vitest.
- Clone this repo or use tiged with:
degit https://github.com/ManUtopiK/vite-fastify-boilerplate- Install:
pnpm installStart dev mode using Vite:
pnpm devStart test mode using Vitest:
pnpm testStart test mode with coverage:
pnpm coverageCompile typescript to javascript:
pnpm buildStart for production:
pnpm start- Main file:
src/app.ts - Configure logger:
src/logger.ts - Change port in
.env
-
Install packages:
pnpm add graphql graphql-tag pnpm add -D vite-plugin-simple-gql
-
Configure
vite.config.ts:import gql from 'vite-plugin-simple-gql'
And add
gql()toplugins:plugins: [gql(), ...]
Now you can import your graphql files in your code:
// example.ts
import MyQuery from './MyQuery.gql'If you would like to make any contribution you are welcome to do so.
@fastify/autoloaddoesn't work.- Websockets doesn't work with vite-plugin-node. See here. To develop with websockets, you should start Fastify as usual.
- Vitest UI doesn't work.
Please create an issue if you found any bugs, to help me improve this project!