Skip to content

Commit 5791f5d

Browse files
authoredMay 23, 2022
docs: split config pages and more (#8270)
1 parent 29659a0 commit 5791f5d

12 files changed

+1030
-986
lines changed
 

‎docs/.vitepress/config.ts

+39
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,45 @@ export default defineConfig({
176176
}
177177
]
178178
}
179+
],
180+
'/config/': [
181+
{
182+
text: 'Config',
183+
items: [
184+
{
185+
text: 'Configuring Vite',
186+
link: '/config/'
187+
},
188+
{
189+
text: 'Shared Options',
190+
link: '/config/shared-options'
191+
},
192+
{
193+
text: 'Server Options',
194+
link: '/config/server-options'
195+
},
196+
{
197+
text: 'Build Options',
198+
link: '/config/build-options'
199+
},
200+
{
201+
text: 'Preview Options',
202+
link: '/config/preview-options'
203+
},
204+
{
205+
text: 'Dep Optimization Options',
206+
link: '/config/dep-optimization-options'
207+
},
208+
{
209+
text: 'SSR Options',
210+
link: '/config/ssr-options'
211+
},
212+
{
213+
text: 'Worker Options',
214+
link: '/config/worker-options'
215+
}
216+
]
217+
}
179218
]
180219
}
181220
}

‎docs/.vitepress/theme/styles/vars.css

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
--vp-c-brand-lighter: #9499ff;
99
--vp-c-brand-dark: #535bf2;
1010
--vp-c-brand-darker: #454ce1;
11+
--vp-c-brand-dimm: rgba(100, 108, 255, 0.08);
1112
}
1213

1314
/**
@@ -39,6 +40,22 @@
3940
);
4041
}
4142

43+
/**
44+
* Component: Custom Block
45+
* -------------------------------------------------------------------------- */
46+
47+
:root {
48+
--vp-custom-block-tip-border: var(--vp-c-brand);
49+
--vp-custom-block-tip-text: var(--vp-c-brand-darker);
50+
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
51+
}
52+
53+
.dark {
54+
--vp-custom-block-tip-border: var(--vp-c-brand);
55+
--vp-custom-block-tip-text: var(--vp-c-brand-lighter);
56+
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
57+
}
58+
4259
/**
4360
* Component: Algolia
4461
* -------------------------------------------------------------------------- */

‎docs/config/build-options.md

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Build Options
2+
3+
## build.target
4+
5+
- **Type:** `string | string[]`
6+
- **Default:** `'modules'`
7+
- **Related:** [Browser Compatibility](/guide/build#browser-compatibility)
8+
9+
Browser compatibility target for the final bundle. The default value is a Vite special value, `'modules'`, which targets browsers with [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import) support.
10+
11+
Another special value is `'esnext'` - which assumes native dynamic imports support and will transpile as little as possible:
12+
13+
- If the [`build.minify`](#build-minify) option is `'terser'`, `'esnext'` will be forced down to `'es2021'`.
14+
- In other cases, it will perform no transpilation at all.
15+
16+
The transform is performed with esbuild and the value should be a valid [esbuild target option](https://esbuild.github.io/api/#target). Custom targets can either be a ES version (e.g. `es2015`), a browser with version (e.g. `chrome58`), or an array of multiple target strings.
17+
18+
Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See [esbuild docs](https://esbuild.github.io/content-types/#javascript) for more details.
19+
20+
## build.polyfillModulePreload
21+
22+
- **Type:** `boolean`
23+
- **Default:** `true`
24+
25+
Whether to automatically inject [module preload polyfill](https://guybedford.com/es-module-preloading-integrity#modulepreload-polyfill).
26+
27+
If set to `true`, the polyfill is auto injected into the proxy module of each `index.html` entry. If the build is configured to use a non-html custom entry via `build.rollupOptions.input`, then it is necessary to manually import the polyfill in your custom entry:
28+
29+
```js
30+
import 'vite/modulepreload-polyfill'
31+
```
32+
33+
Note: the polyfill does **not** apply to [Library Mode](/guide/build#library-mode). If you need to support browsers without native dynamic import, you should probably avoid using it in your library.
34+
35+
## build.outDir
36+
37+
- **Type:** `string`
38+
- **Default:** `dist`
39+
40+
Specify the output directory (relative to [project root](/guide/#index-html-and-project-root)).
41+
42+
## build.assetsDir
43+
44+
- **Type:** `string`
45+
- **Default:** `assets`
46+
47+
Specify the directory to nest generated assets under (relative to `build.outDir`).
48+
49+
## build.assetsInlineLimit
50+
51+
- **Type:** `number`
52+
- **Default:** `4096` (4kb)
53+
54+
Imported or referenced assets that are smaller than this threshold will be inlined as base64 URLs to avoid extra http requests. Set to `0` to disable inlining altogether.
55+
56+
::: tip Note
57+
If you specify `build.lib`, `build.assetsInlineLimit` will be ignored and assets will always be inlined, regardless of file size.
58+
:::
59+
60+
## build.cssCodeSplit
61+
62+
- **Type:** `boolean`
63+
- **Default:** `true`
64+
65+
Enable/disable CSS code splitting. When enabled, CSS imported in async chunks will be inlined into the async chunk itself and inserted when the chunk is loaded.
66+
67+
If disabled, all CSS in the entire project will be extracted into a single CSS file.
68+
69+
::: tip Note
70+
If you specify `build.lib`, `build.cssCodeSplit` will be `false` as default.
71+
:::
72+
73+
## build.cssTarget
74+
75+
- **Type:** `string | string[]`
76+
- **Default:** the same as [`build.target`](/config/#build-target)
77+
78+
This options allows users to set a different browser target for CSS minification from the one used for JavaScript transpilation.
79+
80+
It should only be used when you are targeting a non-mainstream browser.
81+
One example is Android WeChat WebView, which supports most modern JavaScript features but not the [`#RGBA` hexadecimal color notation in CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgb_colors).
82+
In this case, you need to set `build.cssTarget` to `chrome61` to prevent vite from transform `rgba()` colors into `#RGBA` hexadecimal notations.
83+
84+
## build.sourcemap
85+
86+
- **Type:** `boolean | 'inline' | 'hidden'`
87+
- **Default:** `false`
88+
89+
Generate production source maps. If `true`, a separate sourcemap file will be created. If `'inline'`, the sourcemap will be appended to the resulting output file as a data URI. `'hidden'` works like `true` except that the corresponding sourcemap comments in the bundled files are suppressed.
90+
91+
## build.rollupOptions
92+
93+
- **Type:** [`RollupOptions`](https://rollupjs.org/guide/en/#big-list-of-options)
94+
95+
Directly customize the underlying Rollup bundle. This is the same as options that can be exported from a Rollup config file and will be merged with Vite's internal Rollup options. See [Rollup options docs](https://rollupjs.org/guide/en/#big-list-of-options) for more details.
96+
97+
## build.commonjsOptions
98+
99+
- **Type:** [`RollupCommonJSOptions`](https://github.com/rollup/plugins/tree/master/packages/commonjs#options)
100+
101+
Options to pass on to [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/master/packages/commonjs).
102+
103+
## build.dynamicImportVarsOptions
104+
105+
- **Type:** [`RollupDynamicImportVarsOptions`](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#options)
106+
- **Related:** [Dynamic Import](/guide/features#dynamic-import)
107+
108+
Options to pass on to [@rollup/plugin-dynamic-import-vars](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars).
109+
110+
## build.lib
111+
112+
- **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: string | ((format: ModuleFormat) => string) }`
113+
- **Related:** [Library Mode](/guide/build#library-mode)
114+
115+
Build as a library. `entry` is required since the library cannot use HTML as entry. `name` is the exposed global variable and is required when `formats` includes `'umd'` or `'iife'`. Default `formats` are `['es', 'umd']`. `fileName` is the name of the package file output, default `fileName` is the name option of package.json, it can also be defined as function taking the `format` as an argument.
116+
117+
## build.manifest
118+
119+
- **Type:** `boolean | string`
120+
- **Default:** `false`
121+
- **Related:** [Backend Integration](/guide/backend-integration)
122+
123+
When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. When the value is a string, it will be used as the manifest file name.
124+
125+
## build.ssrManifest
126+
127+
- **Type:** `boolean | string`
128+
- **Default:** `false`
129+
- **Related:** [Server-Side Rendering](/guide/ssr)
130+
131+
When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. When the value is a string, it will be used as the manifest file name.
132+
133+
## build.ssr
134+
135+
- **Type:** `boolean | string`
136+
- **Default:** `undefined`
137+
- **Related:** [Server-Side Rendering](/guide/ssr)
138+
139+
Produce SSR-oriented build. The value can be a string to directly specify the SSR entry, or `true`, which requires specifying the SSR entry via `rollupOptions.input`.
140+
141+
## build.minify
142+
143+
- **Type:** `boolean | 'terser' | 'esbuild'`
144+
- **Default:** `'esbuild'`
145+
146+
Set to `false` to disable minification, or specify the minifier to use. The default is [esbuild](https://github.com/evanw/esbuild) which is 20 ~ 40x faster than terser and only 1 ~ 2% worse compression. [Benchmarks](https://github.com/privatenumber/minification-benchmarks)
147+
148+
Note the `build.minify` option is not available when using the `'es'` format in lib mode.
149+
150+
## build.terserOptions
151+
152+
- **Type:** `TerserOptions`
153+
154+
Additional [minify options](https://terser.org/docs/api-reference#minify-options) to pass on to Terser.
155+
156+
## build.write
157+
158+
- **Type:** `boolean`
159+
- **Default:** `true`
160+
161+
Set to `false` to disable writing the bundle to disk. This is mostly used in [programmatic `build()` calls](/guide/api-javascript#build) where further post processing of the bundle is needed before writing to disk.
162+
163+
## build.emptyOutDir
164+
165+
- **Type:** `boolean`
166+
- **Default:** `true` if `outDir` is inside `root`
167+
168+
By default, Vite will empty the `outDir` on build if it is inside project root. It will emit a warning if `outDir` is outside of root to avoid accidentally removing important files. You can explicitly set this option to suppress the warning. This is also available via command line as `--emptyOutDir`.
169+
170+
## build.reportCompressedSize
171+
172+
- **Type:** `boolean`
173+
- **Default:** `true`
174+
175+
Enable/disable gzip-compressed size reporting. Compressing large output files can be slow, so disabling this may increase build performance for large projects.
176+
177+
### build.chunkSizeWarningLimit
178+
179+
- **Type:** `number`
180+
- **Default:** `500`
181+
182+
Limit for chunk size warnings (in kbs).
183+
184+
## build.watch
185+
186+
- **Type:** [`WatcherOptions`](https://rollupjs.org/guide/en/#watch-options)`| null`
187+
- **Default:** `null`
188+
189+
Set to `{}` to enable rollup watcher. This is mostly used in cases that involve build-only plugins or integrations processes.
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Dep Optimization Options
2+
3+
- **Related:** [Dependency Pre-Bundling](/guide/dep-pre-bundling)
4+
5+
## optimizeDeps.entries
6+
7+
- **Type:** `string | string[]`
8+
9+
By default, Vite will crawl all your `.html` files to detect dependencies that need to be pre-bundled (ignoring `node_modules`, `build.outDir`, `__tests__` and `coverage`). If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead.
10+
11+
If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitily defined. If other folders needs to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`.
12+
13+
## optimizeDeps.exclude
14+
15+
- **Type:** `string[]`
16+
17+
Dependencies to exclude from pre-bundling.
18+
19+
:::warning CommonJS
20+
CommonJS dependencies should not be excluded from optimization. If an ESM dependency is excluded from optimization, but has a nested CommonJS dependency, the CommonJS dependency should be added to `optimizeDeps.include`. Example:
21+
22+
```js
23+
export default defineConfig({
24+
optimizeDeps: {
25+
include: ['esm-dep > cjs-dep']
26+
}
27+
})
28+
```
29+
30+
:::
31+
32+
## optimizeDeps.include
33+
34+
- **Type:** `string[]`
35+
36+
By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled.
37+
38+
## optimizeDeps.esbuildOptions
39+
40+
- **Type:** [`EsbuildBuildOptions`](https://esbuild.github.io/api/#simple-options)
41+
42+
Options to pass to esbuild during the dep scanning and optimization.
43+
44+
Certain options are omitted since changing them would not be compatible with Vite's dep optimization.
45+
46+
- `external` is also omitted, use Vite's `optimizeDeps.exclude` option
47+
- `plugins` are merged with Vite's dep plugin

‎docs/config/index.md

+4-981
Large diffs are not rendered by default.

‎docs/config/preview-options.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Preview Options
2+
3+
## preview.host
4+
5+
- **Type:** `string | boolean`
6+
- **Default:** [`server.host`](./server-options#server-host)
7+
8+
Specify which IP addresses the server should listen on.
9+
Set this to `0.0.0.0` or `true` to listen on all addresses, including LAN and public addresses.
10+
11+
This can be set via the CLI using `--host 0.0.0.0` or `--host`.
12+
13+
## preview.port
14+
15+
- **Type:** `number`
16+
- **Default:** `4173`
17+
18+
Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on.
19+
20+
**Example:**
21+
22+
```js
23+
export default defineConfig({
24+
server: {
25+
port: 3030
26+
},
27+
preview: {
28+
port: 8080
29+
}
30+
})
31+
```
32+
33+
## preview.strictPort
34+
35+
- **Type:** `boolean`
36+
- **Default:** [`server.strictPort`](./server-options#server-strictport)
37+
38+
Set to `true` to exit if port is already in use, instead of automatically try the next available port.
39+
40+
## preview.https
41+
42+
- **Type:** `boolean | https.ServerOptions`
43+
- **Default:** [`server.https`](./server-options#server-https)
44+
45+
Enable TLS + HTTP/2. Note this downgrades to TLS only when the [`server.proxy` option](./server-options#server-proxy) is also used.
46+
47+
The value can also be an [options object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) passed to `https.createServer()`.
48+
49+
## preview.open
50+
51+
- **Type:** `boolean | string`
52+
- **Default:** [`server.open`](./server-options#server_open)
53+
54+
Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname. If you want to open the server in a specific browser you like, you can set the env `process.env.BROWSER` (e.g. `firefox`). See [the `open` package](https://github.com/sindresorhus/open#app) for more details.
55+
56+
## preview.proxy
57+
58+
- **Type:** `Record<string, string | ProxyOptions>`
59+
- **Default:** [`server.proxy`](./server-options#server_proxy)
60+
61+
Configure custom proxy rules for the dev server. Expects an object of `{ key: options }` pairs. If the key starts with `^`, it will be interpreted as a `RegExp`. The `configure` option can be used to access the proxy instance.
62+
63+
Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options [here](https://github.com/http-party/node-http-proxy#options).
64+
65+
## preview.cors
66+
67+
- **Type:** `boolean | CorsOptions`
68+
- **Default:** [`server.cors`](./server-options#server_proxy)
69+
70+
Configure CORS for the dev server. This is enabled by default and allows any origin. Pass an [options object](https://github.com/expressjs/cors) to fine tune the behavior or `false` to disable.

‎docs/config/server-options.md

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
# Server Options
2+
3+
## server.host
4+
5+
- **Type:** `string | boolean`
6+
- **Default:** `'127.0.0.1'`
7+
8+
Specify which IP addresses the server should listen on.
9+
Set this to `0.0.0.0` or `true` to listen on all addresses, including LAN and public addresses.
10+
11+
This can be set via the CLI using `--host 0.0.0.0` or `--host`.
12+
13+
## server.port
14+
15+
- **Type:** `number`
16+
- **Default:** `5173`
17+
18+
Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on.
19+
20+
## server.strictPort
21+
22+
- **Type:** `boolean`
23+
24+
Set to `true` to exit if port is already in use, instead of automatically try the next available port.
25+
26+
## server.https
27+
28+
- **Type:** `boolean | https.ServerOptions`
29+
30+
Enable TLS + HTTP/2. Note this downgrades to TLS only when the [`server.proxy` option](#server-proxy) is also used.
31+
32+
The value can also be an [options object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) passed to `https.createServer()`.
33+
34+
## server.open
35+
36+
- **Type:** `boolean | string`
37+
38+
Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname. If you want to open the server in a specific browser you like, you can set the env `process.env.BROWSER` (e.g. `firefox`). See [the `open` package](https://github.com/sindresorhus/open#app) for more details.
39+
40+
**Example:**
41+
42+
```js
43+
export default defineConfig({
44+
server: {
45+
open: '/docs/index.html'
46+
}
47+
})
48+
```
49+
50+
## server.proxy
51+
52+
- **Type:** `Record<string, string | ProxyOptions>`
53+
54+
Configure custom proxy rules for the dev server. Expects an object of `{ key: options }` pairs. If the key starts with `^`, it will be interpreted as a `RegExp`. The `configure` option can be used to access the proxy instance.
55+
56+
Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options [here](https://github.com/http-party/node-http-proxy#options).
57+
58+
In some cases, you might also want to configure the underlying dev server (e.g. to add custom middlewares to the internal [connect](https://github.com/senchalabs/connect) app). In order to do that, you need to write your own [plugin](/guide/using-plugins.html) and use [configureServer](/guide/api-plugin.html#configureserver) function.
59+
60+
**Example:**
61+
62+
```js
63+
export default defineConfig({
64+
server: {
65+
proxy: {
66+
// string shorthand
67+
'/foo': 'http://localhost:4567',
68+
// with options
69+
'/api': {
70+
target: 'http://jsonplaceholder.typicode.com',
71+
changeOrigin: true,
72+
rewrite: (path) => path.replace(/^\/api/, '')
73+
},
74+
// with RegEx
75+
'^/fallback/.*': {
76+
target: 'http://jsonplaceholder.typicode.com',
77+
changeOrigin: true,
78+
rewrite: (path) => path.replace(/^\/fallback/, '')
79+
},
80+
// Using the proxy instance
81+
'/api': {
82+
target: 'http://jsonplaceholder.typicode.com',
83+
changeOrigin: true,
84+
configure: (proxy, options) => {
85+
// proxy will be an instance of 'http-proxy'
86+
}
87+
},
88+
// Proxying websockets or socket.io
89+
'/socket.io': {
90+
target: 'ws://localhost:5173',
91+
ws: true
92+
}
93+
}
94+
}
95+
})
96+
```
97+
98+
## server.cors
99+
100+
- **Type:** `boolean | CorsOptions`
101+
102+
Configure CORS for the dev server. This is enabled by default and allows any origin. Pass an [options object](https://github.com/expressjs/cors) to fine tune the behavior or `false` to disable.
103+
104+
## server.headers
105+
106+
- **Type:** `OutgoingHttpHeaders`
107+
108+
Specify server response headers.
109+
110+
## server.force
111+
112+
- **Type:** `boolean`
113+
- **Related:** [Dependency Pre-Bundling](/guide/dep-pre-bundling)
114+
115+
Set to `true` to force dependency pre-bundling.
116+
117+
## server.hmr
118+
119+
- **Type:** `boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean, clientPort?: number, server?: Server }`
120+
121+
Disable or configure HMR connection (in cases where the HMR websocket must use a different address from the http server).
122+
123+
Set `server.hmr.overlay` to `false` to disable the server error overlay.
124+
125+
`clientPort` is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different port than the client code looks for it on. Useful if you're using an SSL proxy in front of your dev server.
126+
127+
If specifying `server.hmr.server`, Vite will process HMR connection requests through the provided server. If not in middleware mode, Vite will attempt to process HMR connection requests through the existing server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
128+
129+
## server.watch
130+
131+
- **Type:** `object`
132+
133+
File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar#api).
134+
135+
When running Vite on Windows Subsystem for Linux (WSL) 2, if the project folder resides in a Windows filesystem, you'll need to set this option to `{ usePolling: true }`. This is due to [a WSL2 limitation](https://github.com/microsoft/WSL/issues/4739) with the Windows filesystem.
136+
137+
The Vite server watcher skips `.git/` and `node_modules/` directories by default. If you want to watch a package inside `node_modules/`, you can pass a negated glob pattern to `server.watch.ignored`. That is:
138+
139+
```js
140+
export default defineConfig({
141+
server: {
142+
watch: {
143+
ignored: ['!**/node_modules/your-package-name/**']
144+
}
145+
},
146+
// The watched package must be excluded from optimization,
147+
// so that it can appear in the dependency graph and trigger hot reload.
148+
optimizeDeps: {
149+
exclude: ['your-package-name']
150+
}
151+
})
152+
```
153+
154+
## server.middlewareMode
155+
156+
- **Type:** `'ssr' | 'html'`
157+
158+
Create Vite server in middleware mode. (without a HTTP server)
159+
160+
- `'ssr'` will disable Vite's own HTML serving logic so that you should serve `index.html` manually.
161+
- `'html'` will enable Vite's own HTML serving logic.
162+
163+
- **Related:** [SSR - Setting Up the Dev Server](/guide/ssr#setting-up-the-dev-server)
164+
165+
- **Example:**
166+
167+
```js
168+
const express = require('express')
169+
const { createServer: createViteServer } = require('vite')
170+
171+
async function createServer() {
172+
const app = express()
173+
174+
// Create Vite server in middleware mode.
175+
const vite = await createViteServer({
176+
server: { middlewareMode: 'ssr' }
177+
})
178+
// Use vite's connect instance as middleware
179+
app.use(vite.middlewares)
180+
181+
app.use('*', async (req, res) => {
182+
// If `middlewareMode` is `'ssr'`, should serve `index.html` here.
183+
// If `middlewareMode` is `'html'`, there is no need to serve `index.html`
184+
// because Vite will do that.
185+
})
186+
}
187+
188+
createServer()
189+
```
190+
191+
## server.base
192+
193+
- **Type:** `string | undefined`
194+
195+
Prepend this folder to http requests, for use when proxying vite as a subfolder. Should start and end with the `/` character.
196+
197+
## server.fs.strict
198+
199+
- **Type:** `boolean`
200+
- **Default:** `true` (enabled by default since Vite 2.7)
201+
202+
Restrict serving files outside of workspace root.
203+
204+
## server.fs.allow
205+
206+
- **Type:** `string[]`
207+
208+
Restrict files that could be served via `/@fs/`. When `server.fs.strict` is set to `true`, accessing files outside this directory list that aren't imported from an allowed file will result in a 403.
209+
210+
Vite will search for the root of the potential workspace and use it as default. A valid workspace met the following conditions, otherwise will fallback to the [project root](/guide/#index-html-and-project-root).
211+
212+
- contains `workspaces` field in `package.json`
213+
- contains one of the following file
214+
- `lerna.json`
215+
- `pnpm-workspace.yaml`
216+
217+
Accepts a path to specify the custom workspace root. Could be a absolute path or a path relative to [project root](/guide/#index-html-and-project-root). For example:
218+
219+
```js
220+
export default defineConfig({
221+
server: {
222+
fs: {
223+
// Allow serving files from one level up to the project root
224+
allow: ['..']
225+
}
226+
}
227+
})
228+
```
229+
230+
When `server.fs.allow` is specified, the auto workspace root detection will be disabled. To extend the original behavior, a utility `searchForWorkspaceRoot` is exposed:
231+
232+
```js
233+
import { defineConfig, searchForWorkspaceRoot } from 'vite'
234+
235+
export default defineConfig({
236+
server: {
237+
fs: {
238+
allow: [
239+
// search up for workspace root
240+
searchForWorkspaceRoot(process.cwd()),
241+
// your custom rules
242+
'/path/to/custom/allow'
243+
]
244+
}
245+
}
246+
})
247+
```
248+
249+
## server.fs.deny
250+
251+
- **Type:** `string[]`
252+
253+
Blocklist for sensitive files being restricted to be served by Vite dev server.
254+
255+
Default to `['.env', '.env.*', '*.{pem,crt}']`.
256+
257+
## server.origin
258+
259+
- **Type:** `string`
260+
261+
Defines the origin of the generated asset URLs during development.
262+
263+
```js
264+
export default defineConfig({
265+
server: {
266+
origin: 'http://127.0.0.1:8080'
267+
}
268+
})
269+
```

‎docs/config/shared-options.md

+344
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
# Shared Options
2+
3+
## root
4+
5+
- **Type:** `string`
6+
- **Default:** `process.cwd()`
7+
8+
Project root directory (where `index.html` is located). Can be an absolute path, or a path relative to the location of the config file itself.
9+
10+
See [Project Root](/guide/#index-html-and-project-root) for more details.
11+
12+
## base
13+
14+
- **Type:** `string`
15+
- **Default:** `/`
16+
17+
Base public path when served in development or production. Valid values include:
18+
19+
- Absolute URL pathname, e.g. `/foo/`
20+
- Full URL, e.g. `https://foo.com/`
21+
- Empty string or `./` (for embedded deployment)
22+
23+
See [Public Base Path](/guide/build#public-base-path) for more details.
24+
25+
## mode
26+
27+
- **Type:** `string`
28+
- **Default:** `'development'` for serve, `'production'` for build
29+
30+
Specifying this in config will override the default mode for **both serve and build**. This value can also be overridden via the command line `--mode` option.
31+
32+
See [Env Variables and Modes](/guide/env-and-mode) for more details.
33+
34+
## define
35+
36+
- **Type:** `Record<string, string>`
37+
38+
Define global constant replacements. Entries will be defined as globals during dev and statically replaced during build.
39+
40+
- Starting from `2.0.0-beta.70`, string values will be used as raw expressions, so if defining a string constant, it needs to be explicitly quoted (e.g. with `JSON.stringify`).
41+
42+
- To be consistent with [esbuild behavior](https://esbuild.github.io/api/#define), expressions must either be a JSON object (null, boolean, number, string, array, or object) or a single identifier.
43+
44+
- Replacements are performed only when the match isn't surrounded by other letters, numbers, `_` or `$`.
45+
46+
::: warning
47+
Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only.
48+
49+
For example, `process.env.FOO` and `__APP_VERSION__` are good fits. But `process` or `global` should not be put into this option. Variables can be shimmed or polyfilled instead.
50+
:::
51+
52+
::: tip NOTE
53+
For TypeScript users, make sure to add the type declarations in the `env.d.ts` or `vite-env.d.ts` file to get type checks and Intellisense.
54+
55+
Example:
56+
57+
```ts
58+
// vite-env.d.ts
59+
declare const __APP_VERSION__: string
60+
```
61+
62+
:::
63+
64+
::: tip NOTE
65+
Since dev and build implement `define` differently, we should avoid some use cases to avoid inconsistency.
66+
67+
Example:
68+
69+
```js
70+
const obj = {
71+
__NAME__, // Don't define object shorthand property names
72+
__KEY__: value // Don't define object key
73+
}
74+
```
75+
76+
:::
77+
78+
## plugins
79+
80+
- **Type:** `(Plugin | Plugin[])[]`
81+
82+
Array of plugins to use. Falsy plugins are ignored and arrays of plugins are flattened. See [Plugin API](/guide/api-plugin) for more details on Vite plugins.
83+
84+
## publicDir
85+
86+
- **Type:** `string | false`
87+
- **Default:** `"public"`
88+
89+
Directory to serve as plain static assets. Files in this directory are served at `/` during dev and copied to the root of `outDir` during build, and are always served or copied as-is without transform. The value can be either an absolute file system path or a path relative to project root.
90+
91+
Defining `publicDir` as `false` disables this feature.
92+
93+
See [The `public` Directory](/guide/assets#the-public-directory) for more details.
94+
95+
## cacheDir
96+
97+
- **Type:** `string`
98+
- **Default:** `"node_modules/.vite"`
99+
100+
Directory to save cache files. Files in this directory are pre-bundled deps or some other cache files generated by vite, which can improve the performance. You can use `--force` flag or manually delete the directory to regenerate the cache files. The value can be either an absolute file system path or a path relative to project root. Default to `.vite` when no package.json is detected.
101+
102+
## resolve.alias
103+
104+
- **Type:**
105+
`Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`
106+
107+
Will be passed to `@rollup/plugin-alias` as its [entries option](https://github.com/rollup/plugins/tree/master/packages/alias#entries). Can either be an object, or an array of `{ find, replacement, customResolver }` pairs.
108+
109+
When aliasing to file system paths, always use absolute paths. Relative alias values will be used as-is and will not be resolved into file system paths.
110+
111+
More advanced custom resolution can be achieved through [plugins](/guide/api-plugin).
112+
113+
## resolve.dedupe
114+
115+
- **Type:** `string[]`
116+
117+
If you have duplicated copies of the same dependency in your app (likely due to hoisting or linked packages in monorepos), use this option to force Vite to always resolve listed dependencies to the same copy (from project root).
118+
119+
:::warning SSR + ESM
120+
For SSR builds, deduplication does not work for ESM build outputs configured from `build.rollupOptions.output`. A workaround is to use CJS build outputs until ESM has better plugin support for module loading.
121+
:::
122+
123+
## resolve.conditions
124+
125+
- **Type:** `string[]`
126+
127+
Additional allowed conditions when resolving [Conditional Exports](https://nodejs.org/api/packages.html#packages_conditional_exports) from a package.
128+
129+
A package with conditional exports may have the following `exports` field in its `package.json`:
130+
131+
```json
132+
{
133+
"exports": {
134+
".": {
135+
"import": "./index.mjs",
136+
"require": "./index.js"
137+
}
138+
}
139+
}
140+
```
141+
142+
Here, `import` and `require` are "conditions". Conditions can be nested and should be specified from most specific to least specific.
143+
144+
Vite has a list of "allowed conditions" and will match the first condition that is in the allowed list. The default allowed conditions are: `import`, `module`, `browser`, `default`, and `production/development` based on current mode. The `resolve.conditions` config option allows specifying additional allowed conditions.
145+
146+
:::warning Resolving subpath exports
147+
Export keys ending with "/" is deprecated by Node and may not work well. Please contact the package author to use [`*` subpath patterns](https://nodejs.org/api/packages.html#package-entry-points) instead.
148+
:::
149+
150+
## resolve.mainFields
151+
152+
- **Type:** `string[]`
153+
- **Default:** `['module', 'jsnext:main', 'jsnext']`
154+
155+
List of fields in `package.json` to try when resolving a package's entry point. Note this takes lower precedence than conditional exports resolved from the `exports` field: if an entry point is successfully resolved from `exports`, the main field will be ignored.
156+
157+
## resolve.extensions
158+
159+
- **Type:** `string[]`
160+
- **Default:** `['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']`
161+
162+
List of file extensions to try for imports that omit extensions. Note it is **NOT** recommended to omit extensions for custom import types (e.g. `.vue`) since it can interfere with IDE and type support.
163+
164+
## resolve.preserveSymlinks
165+
166+
- **Type:** `boolean`
167+
- **Default:** `false`
168+
169+
Enabling this setting causes vite to determine file identity by the original file path (i.e. the path without following symlinks) instead of the real file path (i.e. the path after following symlinks).
170+
171+
- **Related:** [esbuild#preserve-symlinks](https://esbuild.github.io/api/#preserve-symlinks), [webpack#resolve.symlinks
172+
](https://webpack.js.org/configuration/resolve/#resolvesymlinks)
173+
174+
## css.modules
175+
176+
- **Type:**
177+
```ts
178+
interface CSSModulesOptions {
179+
scopeBehaviour?: 'global' | 'local'
180+
globalModulePaths?: RegExp[]
181+
generateScopedName?:
182+
| string
183+
| ((name: string, filename: string, css: string) => string)
184+
hashPrefix?: string
185+
/**
186+
* default: null
187+
*/
188+
localsConvention?:
189+
| 'camelCase'
190+
| 'camelCaseOnly'
191+
| 'dashes'
192+
| 'dashesOnly'
193+
| null
194+
}
195+
```
196+
197+
Configure CSS modules behavior. The options are passed on to [postcss-modules](https://github.com/css-modules/postcss-modules).
198+
199+
## css.postcss
200+
201+
- **Type:** `string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] })`
202+
203+
Inline PostCSS config or a custom directory to search PostCSS config from (default is project root).
204+
205+
For inline PostCSS config, it expects the same format as `postcss.config.js`. But for `plugins` property, only [array format](https://github.com/postcss/postcss-load-config/blob/main/README.md#array) can be used.
206+
207+
The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config) and only the supported config file names are loaded.
208+
209+
Note if an inline config is provided, Vite will not search for other PostCSS config sources.
210+
211+
## css.preprocessorOptions
212+
213+
- **Type:** `Record<string, object>`
214+
215+
Specify options to pass to CSS pre-processors. The file extensions are used as keys for the options. Example:
216+
217+
```js
218+
export default defineConfig({
219+
css: {
220+
preprocessorOptions: {
221+
scss: {
222+
additionalData: `$injectedColor: orange;`
223+
},
224+
styl: {
225+
additionalData: `$injectedColor ?= orange`
226+
}
227+
}
228+
}
229+
})
230+
```
231+
232+
## css.devSourcemap
233+
234+
- **Experimental**
235+
- **Type:** `boolean`
236+
- **Default:** `false`
237+
238+
Whether to enable sourcemaps during dev.
239+
240+
## json.namedExports
241+
242+
- **Type:** `boolean`
243+
- **Default:** `true`
244+
245+
Whether to support named imports from `.json` files.
246+
247+
## json.stringify
248+
249+
- **Type:** `boolean`
250+
- **Default:** `false`
251+
252+
If set to `true`, imported JSON will be transformed into `export default JSON.parse("...")` which is significantly more performant than Object literals, especially when the JSON file is large.
253+
254+
Enabling this disables named imports.
255+
256+
## esbuild
257+
258+
- **Type:** `ESBuildOptions | false`
259+
260+
`ESBuildOptions` extends [esbuild's own transform options](https://esbuild.github.io/api/#transform-api). The most common use case is customizing JSX:
261+
262+
```js
263+
export default defineConfig({
264+
esbuild: {
265+
jsxFactory: 'h',
266+
jsxFragment: 'Fragment'
267+
}
268+
})
269+
```
270+
271+
By default, esbuild is applied to `ts`, `jsx` and `tsx` files. You can customize this with `esbuild.include` and `esbuild.exclude`, which can be a regex, a [picomatch](https://github.com/micromatch/picomatch#globbing-features) pattern, or an array of either.
272+
273+
In addition, you can also use `esbuild.jsxInject` to automatically inject JSX helper imports for every file transformed by esbuild:
274+
275+
```js
276+
export default defineConfig({
277+
esbuild: {
278+
jsxInject: `import React from 'react'`
279+
}
280+
})
281+
```
282+
283+
Set to `false` to disable esbuild transforms.
284+
285+
## assetsInclude
286+
287+
- **Type:** `string | RegExp | (string | RegExp)[]`
288+
- **Related:** [Static Asset Handling](/guide/assets)
289+
290+
Specify additional [picomatch patterns](https://github.com/micromatch/picomatch#globbing-features) to be treated as static assets so that:
291+
292+
- They will be excluded from the plugin transform pipeline when referenced from HTML or directly requested over `fetch` or XHR.
293+
294+
- Importing them from JS will return their resolved URL string (this can be overwritten if you have a `enforce: 'pre'` plugin to handle the asset type differently).
295+
296+
The built-in asset type list can be found [here](https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts).
297+
298+
**Example:**
299+
300+
```js
301+
export default defineConfig({
302+
assetsInclude: ['**/*.gltf']
303+
})
304+
```
305+
306+
## logLevel
307+
308+
- **Type:** `'info' | 'warn' | 'error' | 'silent'`
309+
310+
Adjust console output verbosity. Default is `'info'`.
311+
312+
## clearScreen
313+
314+
- **Type:** `boolean`
315+
- **Default:** `true`
316+
317+
Set to `false` to prevent Vite from clearing the terminal screen when logging certain messages. Via command line, use `--clearScreen false`.
318+
319+
## envDir
320+
321+
- **Type:** `string`
322+
- **Default:** `root`
323+
324+
The directory from which `.env` files are loaded. Can be an absolute path, or a path relative to the project root.
325+
326+
See [here](/guide/env-and-mode#env-files) for more about environment files.
327+
328+
## envPrefix
329+
330+
- **Type:** `string | string[]`
331+
- **Default:** `VITE_`
332+
333+
Env variables starts with `envPrefix` will be exposed to your client source code via import.meta.env.
334+
335+
:::warning SECURITY NOTES
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+
:::
338+
339+
## spa
340+
341+
- **Type:** `boolean`
342+
- **Default:** `true`
343+
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).

‎docs/config/ssr-options.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SSR Options
2+
3+
- **Related:** [SSR Externals](/guide/ssr#ssr-externals)
4+
5+
:::warning Experimental
6+
SSR options may be adjusted in minor releases.
7+
:::
8+
9+
## ssr.external
10+
11+
- **Type:** `string[]`
12+
13+
Force externalize dependencies for SSR.
14+
15+
## ssr.noExternal
16+
17+
- **Type:** `string | RegExp | (string | RegExp)[] | true`
18+
19+
Prevent listed dependencies from being externalized for SSR. If `true`, no dependencies are externalized.
20+
21+
## ssr.target
22+
23+
- **Type:** `'node' | 'webworker'`
24+
- **Default:** `node`
25+
26+
Build target for the SSR server.

‎docs/config/worker-options.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Worker Options
2+
3+
## worker.format
4+
5+
- **Type:** `'es' | 'iife'`
6+
- **Default:** `iife`
7+
8+
Output format for worker bundle.
9+
10+
## worker.plugins
11+
12+
- **Type:** [`(Plugin | Plugin[])[]`](./shared-options#plugins)
13+
14+
Vite plugins that apply to worker bundle
15+
16+
## worker.rollupOptions
17+
18+
- **Type:** [`RollupOptions`](https://rollupjs.org/guide/en/#big-list-of-options)
19+
20+
Rollup options to build worker bundle.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"typescript": "^4.6.4",
8787
"unbuild": "^0.7.4",
8888
"vite": "workspace:*",
89-
"vitepress": "1.0.0-draft.3",
89+
"vitepress": "1.0.0-draft.4",
9090
"vitest": "^0.12.4",
9191
"vue": "^3.2.33"
9292
},

‎pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.