Skip to content

Commit 42289fa

Browse files
authored
Run pnpm format using new oxfmt version (#359)
1 parent b0345dc commit 42289fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+381
-397
lines changed

docs/guide/getting-started.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const server = Fastify()
6565
await server.register(FastifyVite, {
6666
root: import.meta.dirname, // where to look for vite.config.js
6767
dev: process.argv.includes('--dev'),
68-
spa: true
68+
spa: true,
6969
})
7070

7171
server.get('/', (req, reply) => {
@@ -99,10 +99,7 @@ import viteReact from '@vitejs/plugin-react'
9999

100100
export default {
101101
root: resolve(import.meta.dirname, 'client'),
102-
plugins: [
103-
viteFastify(),
104-
viteReact({ jsxRuntime: 'classic' }),
105-
],
102+
plugins: [viteFastify(), viteReact({ jsxRuntime: 'classic' })],
106103
}
107104
```
108105
@@ -151,10 +148,8 @@ root.render(createApp())
151148
```jsx [client/base.jsx]
152149
import React from 'react'
153150

154-
export function createApp () {
155-
return (
156-
<p>Hello world from React and @fastify/vite!</p>
157-
)
151+
export function createApp() {
152+
return <p>Hello world from React and @fastify/vite!</p>
158153
}
159154
```
160155

docs/guide/known-limitations.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If you're looking into a microfrontend setup, consider [this approach](https://d
1616

1717
## Using @fastify/middie Directly
1818

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:
2020

2121
**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()`.
2222

@@ -30,6 +30,11 @@ import FastifyVite from '@fastify/vite'
3030
const server = Fastify()
3131

3232
// Register middie first - works in both dev and production
33-
await server.register(middie)
34-
await server.register(FastifyVite, { /* options */ })
33+
await server.register(middie, {
34+
/* options */
35+
})
36+
37+
await server.register(FastifyVite, {
38+
/* options */
39+
})
3540
```

docs/guide/rendering-function.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ The default behavior of `prepareClient()` is to just load the module as-is, but
1414
To illustrate, a snippet from the [`react-vanilla`][react-vanilla] SSR example:
1515

1616
```js {4-9}
17-
await server.register(FastifyVite, {
18-
root: import.meta.dirname,
19-
createRenderFunction ({ createApp }) {
20-
return () => {
21-
return {
22-
element: renderToString(createApp())
23-
}
17+
await server.register(FastifyVite, {
18+
root: import.meta.dirname,
19+
createRenderFunction({ createApp }) {
20+
return () => {
21+
return {
22+
element: renderToString(createApp()),
2423
}
2524
}
26-
})
25+
},
26+
})
2727
```
2828

2929
`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:
5656
```jsx [client/base.jsx]
5757
import React from 'react'
5858

59-
export function createApp () {
60-
return (
61-
<p>Hello world from React and** **`@fastify/vite`**!**</p>
62-
)
59+
export function createApp() {
60+
return <p>Hello world from React and** **`@fastify/vite`**!**</p>
6361
}
6462
```
6563

@@ -133,13 +131,13 @@ const server = Fastify()
133131
await server.register(FastifyVite, {
134132
root: import.meta.dirname,
135133
dev: process.argv.includes('--dev'),
136-
createRenderFunction ({ createApp }) {
134+
createRenderFunction({ createApp }) {
137135
return () => {
138136
return {
139-
element: renderToString(createApp())
137+
element: renderToString(createApp()),
140138
}
141139
}
142-
}
140+
},
143141
})
144142

145143
server.get('/', (req, reply) => {

docs/guide/router-integration.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,30 @@ import { uneval } from 'devalue'
5151

5252
export default { createRenderFunction, createRoute }
5353

54-
async function foobarHook (req) {
54+
async function foobarHook(req) {
5555
req.server.log.info(`Hello from ${req.url} and foobarHook`)
5656
}
5757

58-
function createRoute ({ handler, errorHandler, route }, scope, config) {
58+
function createRoute({ handler, errorHandler, route }, scope, config) {
5959
scope.route({
6060
url: route.path,
6161
method: 'GET',
6262
handler,
6363
errorHandler,
64-
...route.addFoobarHook && {
64+
...(route.addFoobarHook && {
6565
onRequest: foobarHook,
66-
}
66+
}),
6767
})
6868
}
6969

70-
function createRenderFunction ({ createApp }) {
70+
function createRenderFunction({ createApp }) {
7171
return async function (server, req, reply) {
7272
const data = { todoList: ['Do laundry', 'Respond to emails', 'Write report'] }
7373
const app = await createApp({ data, server, req, reply }, req.raw.url)
7474
const element = await renderToString(app.instance, app.ctx)
7575
return {
7676
element,
77-
hydration: `<script>window.hydration = ${uneval({ data })}</script>`
77+
hydration: `<script>window.hydration = ${uneval({ data })}</script>`,
7878
}
7979
}
8080
}
@@ -89,8 +89,8 @@ export default [
8989
},
9090
{
9191
path: '/other',
92-
component: () => import('./views/other.vue')
93-
}
92+
component: () => import('./views/other.vue'),
93+
},
9494
]
9595
```
9696

@@ -102,20 +102,22 @@ export default {
102102
// Provides client-side navigation routes to server
103103
routes,
104104
// Provides function needed to perform SSR
105-
createApp
105+
createApp,
106106
}
107107
```
108108

109-
````html [client/index.html]
109+
```html [client/index.html]
110110
<!DOCTYPE html>
111111
<!-- hydration -->
112112
<div id="root"><!-- element --></div>
113113
<script type="module" src="/mount.js"></script>
114+
```
115+
114116
:::
115117

116118
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.
117119

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`.
119121

120122
```mermaid
121123
flowchart TD
@@ -126,7 +128,7 @@ flowchart TD
126128
X[client/routes.js] --> A
127129
B -->D(client/index.html)
128130
C -->|"for (const route of routes)"| G("createRoute(route)")
129-
````
131+
```
130132

131133
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.
132134

docs/guide/templating-function.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ When you run the `vite build` command, `index.html` is what Vite automatically l
1212
```js
1313
import { createHtmlTemplateFunction } from '@fastify/vite/utils'
1414

15-
const template = createHtmlTemplateFunction(
16-
'<main><!-- foobar --></main>'
17-
)
18-
console.log(
19-
template({ foobar: 'This will be inserted' })
20-
)
15+
const template = createHtmlTemplateFunction('<main><!-- foobar --></main>')
16+
console.log(template({ foobar: 'This will be inserted' }))
2117
```
2218

2319
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
2723
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):
2824

2925
```js
30-
function createHtmlFunction (source, scope, config) {
26+
function createHtmlFunction(source, scope, config) {
3127
const indexHtmlTemplate = config.createHtmlTemplateFunction(source)
3228
if (config.spa) {
3329
return function () {
@@ -38,7 +34,7 @@ function createHtmlFunction (source, scope, config) {
3834
}
3935
return async function (ctx) {
4036
this.type('text/html')
41-
this.send(indexHtmlTemplate(ctx ?? await this.render()))
37+
this.send(indexHtmlTemplate(ctx ?? (await this.render())))
4238
return this
4339
}
4440
}

docs/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
layout: home
44

55
hero:
6-
name: "@fastify/vite"
7-
text: "Titans Combined"
6+
name: '@fastify/vite'
7+
text: 'Titans Combined'
88
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>.
99
actions:
1010
- theme: brand
1111
text: Get Started
1212
link: /guide/getting-started
1313
- theme: brand
14-
text: "Vue"
14+
text: 'Vue'
1515
link: /vue/index
1616
- theme: brand
17-
text: "React"
17+
text: 'React'
1818
link: /react/index
1919
image:
2020
src: /fastify-vite.svg
21-
alt: "@fastify/vite"
21+
alt: '@fastify/vite'
2222

23-
title: "@fastify/vite"
23+
title: '@fastify/vite'
2424
titleTemplate: Fastify plugin for Vite integration
2525

2626
features:

docs/react/project-structure.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ The Vite application HTML template:
8888
```html
8989
<!doctype html>
9090
<html lang="en">
91-
<head>
92-
<meta charset="utf-8">
93-
<meta name="viewport" content="width=device-width, initial-scale=1">
94-
</head>
95-
<link rel="stylesheet" href="/base.css" />
96-
<div id="root"><!-- element --></div>
97-
<!-- hydration -->
98-
<script type="module" src="/$app/mount.js"></script>
91+
<head>
92+
<meta charset="utf-8" />
93+
<meta name="viewport" content="width=device-width, initial-scale=1" />
94+
</head>
95+
<link rel="stylesheet" href="/base.css" />
96+
<div id="root"><!-- element --></div>
97+
<!-- hydration -->
98+
<script type="module" src="/$app/mount.js"></script>
9999
</html>
100100
```
101101

@@ -136,8 +136,8 @@ const server = Fastify({
136136
logger: {
137137
transport: {
138138
target: '@fastify/one-line-logger',
139-
}
140-
}
139+
},
140+
},
141141
})
142142

143143
await server.register(FastifyVite, {
@@ -157,10 +157,7 @@ import fastifyReact from '@fastify/react/plugin'
157157

158158
export default {
159159
root: resolve(import.meta.dirname, 'client'),
160-
plugins: [
161-
viteReact(),
162-
fastifyReact(),
163-
],
160+
plugins: [viteReact(), fastifyReact()],
164161
}
165162
```
166163
@@ -178,16 +175,16 @@ export default {
178175
```html [client/index.html]
179176
<!DOCTYPE html>
180177
<html>
181-
<head>
182-
<meta charset="utf-8">
183-
<link rel="stylesheet" href="./base.css">
184-
<!-- head -->
185-
</head>
186-
<body>
187-
<div id="root"><!-- element --></div>
188-
</body>
189-
<!-- hydration -->
190-
<script type="module" src="/$app/mount.js"></script>
178+
<head>
179+
<meta charset="utf-8" />
180+
<link rel="stylesheet" href="./base.css" />
181+
<!-- head -->
182+
</head>
183+
<body>
184+
<div id="root"><!-- element --></div>
185+
</body>
186+
<!-- hydration -->
187+
<script type="module" src="/$app/mount.js"></script>
191188
</html>
192189
```
193190

docs/react/rendering-modes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ import React, { Suspense } from 'react'
4545

4646
export const streaming = true
4747

48-
export default function Index () {
48+
export default function Index() {
4949
return (
5050
<Suspense fallback={<p>Waiting for content</p>}>
5151
<Message />
5252
</Suspense>
5353
)
5454
}
5555

56-
function Message () {
56+
function Message() {
5757
const message = afterSeconds({
5858
id: 'index',
5959
message: 'Delayed by Suspense API',
60-
seconds: 5
60+
seconds: 5,
6161
})
6262
return <p>{message}</p>
6363
}

0 commit comments

Comments
 (0)