@nuxt/docs-nightly 5.0.0-29800730.fb02c57e → 5.0.0-29802865.a46ecec7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -217,6 +217,8 @@ The contract above is deliberately builder-agnostic and works for both the legac
|
|
|
217
217
|
|
|
218
218
|
For a custom builder you only need to satisfy the generic contract. The Vite Environment API integration (`experimental.nitroViteEnvironment`) is specific to `@nuxt/vite-builder`; other builders, including custom ones, use the legacy Nitro Rollup path.
|
|
219
219
|
|
|
220
|
+
Which of the two paths is in use is decided by the *server* builder, not by the flag directly: a server builder declares whether its build is a pass of its own, run after the app build, or an environment of the app builder's build. `@nuxt/nitro-server` declares it from `experimental.nitroViteEnvironment`, and a server builder with no build pass of its own (such as `@nuxt/vite-server`) declares that Vite is building everything.
|
|
221
|
+
|
|
220
222
|
::read-more{to="/docs/4.x/guide/going-further/internals"}
|
|
221
223
|
Learn more about the Nuxt interface and the build vs. runtime split.
|
|
222
224
|
::
|
package/4.api/5.kit/12.nitro.md
CHANGED
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Nitro is an open source TypeScript framework to build ultra-fast web servers. Nuxt uses Nitro as its server engine. You can use `useNitro` to access the Nitro instance, `addServerHandler` to add a server handler, `addDevServerHandler` to add a server handler to be used only in development mode, `addServerPlugin` to add a plugin to extend Nitro's runtime behavior, and `addPrerenderRoutes` to add routes to be prerendered by Nitro.
|
|
11
|
+
Nitro is an open source TypeScript framework to build ultra-fast web servers. Nuxt uses Nitro as its server engine. You can use `useNitro` to access the Nitro instance (or `tryUseNitro` if your module should also work without Nitro), `addServerHandler` to add a server handler, `addDevServerHandler` to add a server handler to be used only in development mode, `addServerPlugin` to add a plugin to extend Nitro's runtime behavior, and `addPrerenderRoutes` to add routes to be prerendered by Nitro.
|
|
12
12
|
|
|
13
13
|
## `addServerHandler`
|
|
14
14
|
|
|
@@ -191,6 +191,40 @@ export default defineNuxtModule({
|
|
|
191
191
|
function useNitro (): Nitro
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
+
## `tryUseNitro`
|
|
195
|
+
|
|
196
|
+
Returns the Nitro instance, or `undefined` when there is none.
|
|
197
|
+
|
|
198
|
+
There is no Nitro instance before the `ready` hook has run, and none at all when the
|
|
199
|
+
configured [`server.builder`](/docs/api/nuxt-config#builder-1) does not use Nitro, such as a
|
|
200
|
+
builder that outputs a client-only SPA. Use this rather than `useNitro()` for anything that
|
|
201
|
+
should keep working without a server: server routes, route rules and prerendering are all
|
|
202
|
+
absent in that case.
|
|
203
|
+
|
|
204
|
+
### Usage
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { defineNuxtModule, tryUseNitro } from '@nuxt/kit'
|
|
208
|
+
|
|
209
|
+
export default defineNuxtModule({
|
|
210
|
+
setup (options, nuxt) {
|
|
211
|
+
nuxt.hook('ready', () => {
|
|
212
|
+
const nitro = tryUseNitro()
|
|
213
|
+
if (!nitro) {
|
|
214
|
+
// no server: skip anything that would only run there
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
},
|
|
219
|
+
})
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Type
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
function tryUseNitro (): Nitro | undefined
|
|
226
|
+
```
|
|
227
|
+
|
|
194
228
|
## `addServerPlugin`
|
|
195
229
|
|
|
196
230
|
Add plugin to extend Nitro's runtime behavior.
|
package/4.api/6.nuxt-config.md
CHANGED
|
@@ -1317,6 +1317,8 @@ Specify the server builder to use for bundling the server part of your applicati
|
|
|
1317
1317
|
|
|
1318
1318
|
By default, Nuxt uses `@nuxt/nitro-server`, which provides standalone Nitro integration. This architecture allows for different Nitro integration patterns, such as using Nitro as a Vite plugin (with the Vite Environment API).
|
|
1319
1319
|
|
|
1320
|
+
`"nitro"` and `"vite"` are shorthands for `@nuxt/nitro-server` and `@nuxt/vite-server`. The latter is experimental and implemented with Vite alone: it builds the client and ships no server of its own, so with `ssr: false` it produces a static SPA. With SSR enabled the server environment is still built, but running it is left to a Vite plugin that brings its own target or to a custom server. Server routes, route rules and prerendering are unavailable, and modules that need a server will not work.
|
|
1321
|
+
|
|
1320
1322
|
- **Type**: `string | { bundle: (nuxt: Nuxt) => Promise<void> }`
|
|
1321
1323
|
- **Default:** `"@nuxt/nitro-server"`
|
|
1322
1324
|
|