Open meotimdihia opened 2 years ago
I think it can do it because of money. Vercel pays devs to work on the Next.js framework full-time.
Vercel raises $150M Series D as it looks to build an end-to-end front-end development platform
"Hot reload" or HMR (Hot module replacement) is something backend devs are trying to solve for a long time,
But AFAIK its more linked to the build system than just the framework alone, eg: Nest JS's hot reload sits on top of Webpack's HMR system. https://docs.nestjs.com/recipes/hot-reload
So maybe if Fastify creates an integration with Vite or something then it might be possible to do.
I probably just scratched the surface but I think @mcollina was doing something with HMR in Node servers.
Hi, I just have used fastify-cli@5
again. It is faster than other solutions. 👍 I ditched ts-node
, and cut down 50% reload time.
@meotimdihia If speed is the main thing you're looking for, I've had some good experiences using tsx
https://github.com/esbuild-kit/tsx
@sidwebworks I just tested it, it is faster than ts-node
but not faster than fastify-cli
.
Haha good for us I guess, Fastify stands strong in being the fastest.
@sidwebworks I just tested it, it is faster than
ts-node
but not faster thanfastify-cli
.
Idk sir what are your requirements, but for me tsx's been the fastest irrespective of codebase size.
I have refactored one generated by fastify cli with --lang=ts using bob-ts for simplicity https://github.com/ekoeryanto/fastify-esbuild
should we implement it here, maybe with --bob arg?
For the current state of my project, this is the biggest problem. I am thinking switch to Next.js API. Because debug experience in Fastify is not good for a big project in my idea, I don't know how everyone deals with this. But for me, it is very bad.
Anyway, I often need to restart the dev server 10-20 times/per day if I am working on the API.
We have a working but sometimes crashing version of it in https://oss.platformatic.dev/. Check out platformatic service, as it has no database component.
The technique that Next.js uses requires quite a lot of transpilation and it leaks memory. We are working on a better and more native solution to this problem. Once it stabilizes, it could be used in fastify-cli.
@mcollina I tried Platformatic, and it sounds good. I have some suggestions:
fastify-cli
to Platformatic. Hopefully, we have a guide about this.react-admin
. It is great if Platformatic DB compatible with react-admin
.I hope it is stable soon.
While waiting for other solutions, I can get tsup
to work now, it is very fast in comparison with other solutions.
x3-x4 times startup for me.
This is my configuration for tsup
tsup.config.ts
import { defineConfig } from "tsup"
export default defineConfig({
entry: [
"src/web/index.ts",
"src/web/plugins/**/*.ts",
"src/web/routes/**/*.ts",
"prisma/**/*.ts"
],
bundle: true,
platform: "node",
target: "node18",
sourcemap: true,
clean: true
})
package.json
"scripts": {
"dev": "export NODE_OPTIONS='--enable-source-maps' && tsup --watch --onSuccess \"fastify start --port 3002 --options -l info -P dist/src/web/index.js\"",
}
Related to https://github.com/fastify/fastify-cli/issues/487
@mcollina Does fastify support any Hot Module Replacement or is it always required to restart the server?
You can try platformatic service for a hot module replacement solution.
I think this would trickle down to this module once it's a bit more stable.
I managed to use Vite's HMR functionality to auto restart the Fastify server, and I was wondering if there is a more efficient way. I think platformatic uses the same approach?
@stefanvanherwijnen Do you know any articles about how to use Vitejs to reload the API code? I think Vitejs just reload the frontend code.
Basically, once you have Fastify running in Vite, use handleHotUpdate to recreate the server. Also have a look at @fastify/restartable, but I couldn't get it to work because the arguments differ slightly from Fastify server.
We have a working but sometimes crashing version of it in https://oss.platformatic.dev/. Check out platformatic service, as it has no database component.
The technique that Next.js uses requires quite a lot of transpilation and it leaks memory. We are working on a better and more native solution to this problem. Once it stabilizes, it could be used in fastify-cli.
Has there been any movement on this (hot reload for fastify apps) issue. The new fastify-vite docs have convinced me this may be worth the effort. Then, I remembered the potential DX hit we'd be incurring due to having to restart the entire server on every change. This could be an overblown concern, but for large apps (especially when debugging) this seems like a huge cost.
I did a bit of reading on platformatic service but I couldn't make heads or tails of what it really is or how it's relevant to this issue 🤔
All of the above is solved in Platformatic: Fast hot reload with TS support. it's a supercharged Fastify;).
Prerequisites
🚀 Feature Proposal
Hi, my project has a lot of routes ~100 routes and ~150 dependencies. And everything is slowing down. I used all tools
nodemon
,ts-node
,ts-node-dev
,backpack
andfastify-cli
(v4) I even purchase a new good CPU with a benchmark score is 24000 But my project still takes 4-5s to restart when a file is changed.I am using Next.js too. And I am curious why Next.js never needs to restart the server, but other node.js frameworks can't do that 🤔
Motivation
Everyone is happy.
Example
No response