Skip to content

Commit 5791f5d

Browse files
authored
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

0 commit comments

Comments
 (0)