You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/known-limitations.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ If you're looking into a microfrontend setup, consider [this approach](https://d
16
16
17
17
## Using @fastify/middie Directly
18
18
19
-
`@fastify/vite` internally registers `@fastify/middie` in **development mode** to run Vite's dev server middleware. If you need to use middie yourself:
19
+
`@fastify/vite` internally registers `@fastify/middie` in **development mode** to run Vite's dev server middleware. If you want to use middie yourself with different options:
20
20
21
21
**In development mode:** You can either register middie before `@fastify/vite` (it will detect this and skip its own registration), or simply use `server.use()` after calling `server.vite.ready()`.
22
22
@@ -30,6 +30,11 @@ import FastifyVite from '@fastify/vite'
30
30
constserver=Fastify()
31
31
32
32
// Register middie first - works in both dev and production
Copy file name to clipboardExpand all lines: docs/guide/rendering-function.md
+13-15Lines changed: 13 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,16 +14,16 @@ The default behavior of `prepareClient()` is to just load the module as-is, but
14
14
To illustrate, a snippet from the [`react-vanilla`][react-vanilla] SSR example:
15
15
16
16
```js {4-9}
17
-
awaitserver.register(FastifyVite, {
18
-
root:import.meta.dirname,
19
-
createRenderFunction ({ createApp }) {
20
-
return () => {
21
-
return {
22
-
element:renderToString(createApp())
23
-
}
17
+
awaitserver.register(FastifyVite, {
18
+
root:import.meta.dirname,
19
+
createRenderFunction({ createApp }) {
20
+
return () => {
21
+
return {
22
+
element:renderToString(createApp()),
24
23
}
25
24
}
26
-
})
25
+
},
26
+
})
27
27
```
28
28
29
29
`createRenderFunction()` receives as the first parameter a reference to your **Vite application module**, i.e., your client application. The function it returns is added ([decorated](https://fastify.dev/docs/v2.15.x/Documentation/Decorators/)) to the Fastify `Reply` class as `render()`.
@@ -56,10 +56,8 @@ Let's focus on the main React component:
56
56
```jsx [client/base.jsx]
57
57
importReactfrom'react'
58
58
59
-
exportfunctioncreateApp () {
60
-
return (
61
-
<p>Hello world from React and****`@fastify/vite`**!**</p>
62
-
)
59
+
exportfunctioncreateApp() {
60
+
return<p>Hello world from React and****`@fastify/vite`**!**</p>
hydration:`<script>window.hydration = ${uneval({ data })}</script>`
77
+
hydration:`<script>window.hydration = ${uneval({ data })}</script>`,
78
78
}
79
79
}
80
80
}
@@ -89,8 +89,8 @@ export default [
89
89
},
90
90
{
91
91
path:'/other',
92
-
component: () =>import('./views/other.vue')
93
-
}
92
+
component: () =>import('./views/other.vue'),
93
+
},
94
94
]
95
95
```
96
96
@@ -102,20 +102,22 @@ export default {
102
102
// Provides client-side navigation routes to server
103
103
routes,
104
104
// Provides function needed to perform SSR
105
-
createApp
105
+
createApp,
106
106
}
107
107
```
108
108
109
-
````html [client/index.html]
109
+
```html [client/index.html]
110
110
<!DOCTYPE html>
111
111
<!-- hydration -->
112
112
<divid="root"><!-- element --></div>
113
113
<scripttype="module"src="/mount.js"></script>
114
+
```
115
+
114
116
:::
115
117
116
118
The key thing to understand in this example is that **`@fastify/vite`** automatically executes [`createRoute()`](/config/#createroute)**for each of the routes defined** in the **`routes`** key from your client module default export.
117
119
118
-
As long as each object in the `routes` array (or function returning an array) has a `path` property, **`@fastify/vite`** will use it to register an individual Fastify route for your client-side route, by default. By providing your own [`createRoute()`](/config/#createroute) definition, you can customize it however you want. In this example, `client/routes.js` is shared by `client/base.js` and `client/index.js`, which *also* imports `client/base.js`.
120
+
As long as each object in the `routes` array (or function returning an array) has a `path` property, **`@fastify/vite`** will use it to register an individual Fastify route for your client-side route, by default. By providing your own [`createRoute()`](/config/#createroute) definition, you can customize it however you want. In this example, `client/routes.js` is shared by `client/base.js` and `client/index.js`, which _also_ imports `client/base.js`.
119
121
120
122
```mermaid
121
123
flowchart TD
@@ -126,7 +128,7 @@ flowchart TD
126
128
X[client/routes.js] --> A
127
129
B -->D(client/index.html)
128
130
C -->|"for (const route of routes)"| G("createRoute(route)")
129
-
````
131
+
```
130
132
131
133
Notice how `addFoobarHook` is a flag set in one of the client-side routes (in `client/routes.js`), just to demonstrante how it can be used to customize route registration, in this case setting `foobarHook` as an [`onRequest`](https://fastify.dev/docs/latest/Reference/Hooks/#onrequest) hook.
console.log(template({ foobar:'This will be inserted' }))
21
17
```
22
18
23
19
The snippet above prints out `<main>This will be inserted</main>`.
@@ -27,7 +23,7 @@ By default, that function is used internally by the `createHtmlFunction()` confi
27
23
Notice that `createHtmlTemplateFunction()` is not only a utility you can import from `@fastify/vite/utils`, but is also set as configuration hook within `@fastify/vite`. If you want to use a different templating engine, just provide a different `createHtmlTemplateFunction()` implementation and it will be automatically used by the [**default definition of `createHtmlFunction()`**](https://github.com/fastify/fastify-vite/blob/dev/packages/fastify-vite/config.js#L58):
Copy file name to clipboardExpand all lines: docs/index.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,24 +3,24 @@
3
3
layout: home
4
4
5
5
hero:
6
-
name: "@fastify/vite"
7
-
text: "Titans Combined"
6
+
name: '@fastify/vite'
7
+
text: 'Titans Combined'
8
8
tagline: Cleanly and elegantly integrate <b><a href="https://fastify.dev/" target="_blank">Fastify</a></b> and <b><a href="https://vitejs.dev/" target="_blank">Vite</a></b> to create a <b>minimal</b>, <b>low overhead</b> setup for <b>full stack monoliths</b>.
9
9
actions:
10
10
- theme: brand
11
11
text: Get Started
12
12
link: /guide/getting-started
13
13
- theme: brand
14
-
text: "Vue"
14
+
text: 'Vue'
15
15
link: /vue/index
16
16
- theme: brand
17
-
text: "React"
17
+
text: 'React'
18
18
link: /react/index
19
19
image:
20
20
src: /fastify-vite.svg
21
-
alt: "@fastify/vite"
21
+
alt: '@fastify/vite'
22
22
23
-
title: "@fastify/vite"
23
+
title: '@fastify/vite'
24
24
titleTemplate: Fastify plugin for Vite integration
0 commit comments