Skip to content

Commit 47f9f1c

Browse files
authored
Merge branch 'main' into main
2 parents 4dc672f + b9a4cc6 commit 47f9f1c

Some content is hidden

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

60 files changed

+1405
-266
lines changed

docs/config/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ You can also explicitly specify a config file to use with the `--config` CLI opt
2222
vite --config my-config.js
2323
```
2424

25+
::: tip BUNDLING THE CONFIG
26+
By default, Vite uses `esbuild` to bundle the config into a temporary file. This can cause issues when importing TypeScript files in a monorepo. If you encounter any issues with this approach, you can specify `--configLoader=runner` to use the module runner instead - it will not create a temporary config and will transform any files on the fly. Note that module runner doesn't support CJS in config files, but external CJS packages should work as usual.
27+
:::
28+
2529
## Config Intellisense
2630

2731
Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints:

docs/config/preview-options.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ See [`server.host`](./server-options#server-host) for more details.
1919

2020
:::
2121

22+
## preview.allowedHosts
23+
24+
- **Type:** `string | true`
25+
- **Default:** [`server.allowedHosts`](./server-options#server-allowedhosts)
26+
27+
The hostnames that Vite is allowed to respond to.
28+
29+
See [`server.allowedHosts`](./server-options#server-allowedhosts) for more details.
30+
2231
## preview.port
2332

2433
- **Type:** `number`
@@ -78,7 +87,9 @@ Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options
7887
- **Type:** `boolean | CorsOptions`
7988
- **Default:** [`server.cors`](./server-options#server-cors)
8089

81-
Configure CORS for the preview server. This is enabled by default and allows any origin. Pass an [options object](https://github.com/expressjs/cors#configuration-options) to fine tune the behavior or `false` to disable.
90+
Configure CORS for the preview server.
91+
92+
See [`server.cors`](./server-options#server-cors) for more details.
8293

8394
## preview.headers
8495

docs/config/server-options.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ See [the WSL document](https://learn.microsoft.com/en-us/windows/wsl/networking#
4242

4343
:::
4444

45+
## server.allowedHosts
46+
47+
- **Type:** `string[] | true`
48+
- **Default:** `[]`
49+
50+
The hostnames that Vite is allowed to respond to.
51+
`localhost` and domains under `.localhost` and all IP addresses are allowed by default.
52+
When using HTTPS, this check is skipped.
53+
54+
If a string starts with `.`, it will allow that hostname without the `.` and all subdomains under the hostname. For example, `.example.com` will allow `example.com`, `foo.example.com`, and `foo.bar.example.com`.
55+
56+
If set to `true`, the server is allowed to respond to requests for any hosts.
57+
This is not recommended as it will be vulnerable to DNS rebinding attacks.
58+
4559
## server.port
4660

4761
- **Type:** `number`
@@ -147,8 +161,15 @@ export default defineConfig({
147161
## server.cors
148162

149163
- **Type:** `boolean | CorsOptions`
164+
- **Default:** `{ origin: /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/ }` (allows localhost, `127.0.0.1` and `::1`)
150165

151-
Configure CORS for the dev server. This is enabled by default and allows any origin. Pass an [options object](https://github.com/expressjs/cors#configuration-options) to fine tune the behavior or `false` to disable.
166+
Configure CORS for the dev server. Pass an [options object](https://github.com/expressjs/cors#configuration-options) to fine tune the behavior or `true` to allow any origin.
167+
168+
:::warning
169+
170+
We recommend setting a specific value rather than `true` to avoid exposing the source code to untrusted origins.
171+
172+
:::
152173

153174
## server.headers
154175

docs/guide/api-environment-frameworks.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ The `runner` is evaluated eagerly when it's accessed for the first time. Beware
4646
Given a Vite server configured in middleware mode as described by the [SSR setup guide](/guide/ssr#setting-up-the-dev-server), let's implement the SSR middleware using the environment API. Error handling is omitted.
4747

4848
```js
49+
import fs from 'node:fs'
50+
import path from 'node:path'
51+
import { fileURLToPath } from 'node:url'
4952
import { createServer } from 'vite'
5053

54+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
55+
5156
const server = await createServer({
5257
server: { middlewareMode: true },
5358
appType: 'custom',

docs/guide/backend-integration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ If you need a custom integration, you can follow the steps in this guide to conf
1212
import { defineConfig } from 'vite'
1313
// ---cut---
1414
export default defineConfig({
15+
server: {
16+
cors: {
17+
// the origin you will be accessing via browser
18+
origin: 'http://my-backend.example.com',
19+
},
20+
},
1521
build: {
1622
// generate .vite/manifest.json in outDir
1723
manifest: true,

docs/guide/build.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ When it is time to deploy your app for production, simply run the `vite build` c
44

55
## Browser Compatibility
66

7-
The production bundle assumes support for modern JavaScript. By default, Vite targets browsers which support the [native ES Modules](https://caniuse.com/es6-module), [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta):
7+
By default, the production bundle assumes support for modern JavaScript, including [native ES Modules](https://caniuse.com/es6-module), [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta). The default browser support range is:
88

99
- Chrome >=87
1010
- Firefox >=78
1111
- Safari >=14
1212
- Edge >=88
1313

14-
You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`.
14+
You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`. If a lower target is set, Vite will still require these minimum browser support ranges as it relies on [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import) and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta):
15+
16+
- Chrome >=64
17+
- Firefox >=67
18+
- Safari >=11.1
19+
- Edge >=79
1520

1621
Note that by default, Vite only handles syntax transforms and **does not cover polyfills**. You can check out https://cdnjs.cloudflare.com/polyfill/ which automatically generates polyfill bundles based on the user's browser UserAgent string.
1722

@@ -106,9 +111,12 @@ During dev, simply navigate or link to `/nested/` - it works as expected, just l
106111
During build, all you need to do is to specify multiple `.html` files as entry points:
107112

108113
```js twoslash [vite.config.js]
109-
import { resolve } from 'path'
114+
import { dirname, resolve } from 'node:path'
115+
import { fileURLToPath } from 'node:url'
110116
import { defineConfig } from 'vite'
111117

118+
const __dirname = dirname(fileURLToPath(import.meta.url))
119+
112120
export default defineConfig({
113121
build: {
114122
rollupOptions: {
@@ -134,9 +142,12 @@ When it is time to bundle your library for distribution, use the [`build.lib` co
134142
::: code-group
135143
136144
```js twoslash [vite.config.js (single entry)]
137-
import { resolve } from 'path'
145+
import { dirname, resolve } from 'node:path'
146+
import { fileURLToPath } from 'node:url'
138147
import { defineConfig } from 'vite'
139148

149+
const __dirname = dirname(fileURLToPath(import.meta.url))
150+
140151
export default defineConfig({
141152
build: {
142153
lib: {
@@ -162,9 +173,12 @@ export default defineConfig({
162173
```
163174
164175
```js twoslash [vite.config.js (multiple entries)]
165-
import { resolve } from 'path'
176+
import { dirname, resolve } from 'node:path'
177+
import { fileURLToPath } from 'node:url'
166178
import { defineConfig } from 'vite'
167179

180+
const __dirname = dirname(fileURLToPath(import.meta.url))
181+
168182
export default defineConfig({
169183
build: {
170184
lib: {

0 commit comments

Comments
 (0)