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/config/shared-options.md
+10-4
Original file line number
Diff line number
Diff line change
@@ -336,9 +336,15 @@ Env variables starts with `envPrefix` will be exposed to your client source code
336
336
`envPrefix` should not be set as `''`, which will expose all your env variables and cause unexpected leaking of of sensitive information. Vite will throw error when detecting `''`.
337
337
:::
338
338
339
-
## spa
339
+
## appType
340
340
341
-
-**Type:**`boolean`
342
-
-**Default:**`true`
341
+
-**Type:**`'spa' | 'mpa' | 'custom'`
342
+
-**Default:**`'spa'`
343
+
344
+
Whether your application is a Single Page Application (SPA), a [Multi Page Application (MPA)](../guide/build#multi-page-app), or Custom Application (SSR and frameworks with custom HTML handling):
345
+
346
+
-`'spa'`: include SPA fallback middleware and configure [sirv](https://github.com/lukeed/sirv) with `single: true` in preview
347
+
-`'mpa'`: only include non-SPA HTML middlewares
348
+
-`'custom'`: don't include HTML middlewares
343
349
344
-
Whether your application is a Single Page Application (SPA). Set to `false` for other kinds of apps like MPAs. Learn more in Vite's [SSR guide](/guide/ssr#vite-cli).
350
+
Learn more in Vite's [SSR guide](/guide/ssr#vite-cli). Related: [`server.middlewareMode`](./server-options#servermiddlewaremode).
// Create Vite server in middleware mode. This disables Vite's own HTML
78
-
// serving logic and let the parent server take control.
79
-
//
80
-
// In middleware mode, if you want to use Vite's own HTML serving logic
81
-
// use `'html'` as the `middlewareMode` (ref https://vitejs.dev/config/#server-middlewaremode)
77
+
// Create Vite server in middleware mode and configure the app type as
78
+
// 'custom', disabling Vite's own HTML serving logic so parent server
79
+
// can take control
82
80
constvite=awaitcreateViteServer({
83
-
server: { middlewareMode:'ssr' }
81
+
server: { middlewareMode:true },
82
+
appType:'custom'
84
83
})
85
84
// use vite's connect instance as middleware
86
85
app.use(vite.middlewares)
@@ -267,11 +266,8 @@ In some cases like `webworker` runtimes, you might want to bundle your SSR build
267
266
268
267
## Vite CLI
269
268
270
-
The CLI commands `$ vite dev` and `$ vite preview` can also be used for SSR apps:
269
+
The CLI commands `$ vite dev` and `$ vite preview` can also be used for SSR apps. You can add your SSR middlewares to the development server with [`configureServer`](/guide/api-plugin#configureserver) and to the preview server with [`configurePreviewServer`](/guide/api-plugin#configurepreviewserver).
271
270
272
-
1. Add your SSR middleware to the development server with [`configureServer`](/guide/api-plugin#configureserver) and to the preview server with [`configurePreviewServer`](/guide/api-plugin#configurepreviewserver).
273
-
:::tip Note
274
-
Use a post hook so that your SSR middleware runs _after_ Vite's middlewares.
275
-
:::
276
-
277
-
2. Set `config.spa` to `false`. This switches the development and preview server from SPA mode to SSR/MPA mode.
271
+
:::tip Note
272
+
Use a post hook so that your SSR middleware runs _after_ Vite's middlewares.
0 commit comments