|
1 | 1 | # Known Limitations |
2 | 2 |
|
3 | | -- It's currently impossible to run **`@fastify/vite`** in an encapsulated Fastify plugin. You'll need to register **`@fastify/vite`** at the root context, or if you want to use it in a plugin, that plugin must be wrapped in [`fastify-plugin`](https://github.com/fastify/fastify-plugin) so it's also registered at the root context. |
| 3 | +## Encapsulated Plugin Registration |
4 | 4 |
|
5 | | - > Investigation on this has started but is still pending — everything points to **`@fastify/middie`**, the Express compatibility layer needed to run the Vite development server middleware. It's just considered low-prio at the moment as in most setups, only a single instance is needed anyway. |
| 5 | +It's currently impossible to run `@fastify/vite` in an encapsulated Fastify plugin. You'll need to register `@fastify/vite` at the root context, or if you want to use it in a plugin, that plugin must be wrapped in [`fastify-plugin`](https://github.com/fastify/fastify-plugin) so it's also registered at the root context. |
6 | 6 |
|
7 | | -- It's currently impossible to run **multiple** Vite development server middleware in your Fastify server, which means `@fastify/vite` can **only be registered once**. Configuration for this is somewhat tricky and there isn't documentation on how to do it. Once [#108](https://github.com/fastify/fastify-vite/pull/108) is completed and merged, it will open the path to have a Vite development server factory that can create instances on-demand, but that approach still remains to be tested. |
| 7 | +::: info |
| 8 | +Investigation on this has started but is still pending — everything points to `@fastify/middie`, the Express compatibility layer needed to run the Vite development server middleware. It's just considered low-prio at the moment as in most setups, only a single instance is needed anyway. |
| 9 | +::: |
8 | 10 |
|
9 | | - If you're looking into a microfrontend setup, consider [this approach](https://dev.to/getjv/react-micro-frontends-with-vite-5442). |
| 11 | +## Multiple Vite Instances |
| 12 | + |
| 13 | +It's currently impossible to run **multiple** Vite development server middleware in your Fastify server, which means `@fastify/vite` can **only be registered once**. Configuration for this is somewhat tricky and there isn't documentation on how to do it. Once [#108](https://github.com/fastify/fastify-vite/pull/108) is completed and merged, it will open the path to have a Vite development server factory that can create instances on-demand, but that approach still remains to be tested. |
| 14 | + |
| 15 | +If you're looking into a microfrontend setup, consider [this approach](https://dev.to/getjv/react-micro-frontends-with-vite-5442). |
| 16 | + |
| 17 | +## Using @fastify/middie Directly |
| 18 | + |
| 19 | +`@fastify/vite` internally registers `@fastify/middie` to run Vite's development server middleware. If you need to register `@fastify/middie` yourself (e.g., to pass custom options), register it **before** `@fastify/vite`: |
| 20 | + |
| 21 | +```js |
| 22 | +import Fastify from 'fastify' |
| 23 | +import middie from '@fastify/middie' |
| 24 | +import FastifyVite from '@fastify/vite' |
| 25 | + |
| 26 | +const server = Fastify() |
| 27 | + |
| 28 | +// Register middie first with your options |
| 29 | +await server.register(middie, { /* your options */ }) |
| 30 | +await server.register(FastifyVite, { /* options */ }) |
| 31 | +``` |
| 32 | + |
| 33 | +`@fastify/vite` checks if middie is already registered and skips its own registration if so. |
0 commit comments