Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 24, 2025
2 parents a1394bf + eb22a74 commit d00ce43
Show file tree
Hide file tree
Showing 141 changed files with 4,438 additions and 2,218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@bab30c2299617f6615ec02a68b9a40d10bd21366 # v45.0.5
uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6
with:
files: |
docs/**
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export default defineConfig({
link: '/guide/api-environment',
},
{
text: 'Environment instances',
text: 'Environment Instances',
link: '/guide/api-environment-instances',
},
{
Expand Down Expand Up @@ -442,7 +442,7 @@ export default defineConfig({
transformPageData(pageData) {
const canonicalUrl = `${ogUrl}/${pageData.relativePath}`
.replace(/\/index\.md$/, '/')
.replace(/\.md$/, '/')
.replace(/\.md$/, '')
pageData.frontmatter.head ??= []
pageData.frontmatter.head.unshift(
['link', { rel: 'canonical', href: canonicalUrl }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import logoLaravel from './images/laravel.svg'
import logoAdonis from './images/adonis.svg'
import logoEmber from './images/ember.svg'
import logoPreact from './images/preact.svg'
import logoHono from './images/hono.svg'
/**
* The frameworks and tools to display in this section.
Expand Down Expand Up @@ -164,6 +165,13 @@ const frameworks: Framework[] = [
url: 'https://emberjs.com/',
visible: ref(false),
},
{
name: 'Hono',
logo: logoHono,
color: '#ff5c13',
url: 'https://hono.dev/',
visible: ref(false),
},
]
// Starting parameters
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ You can also explicitly specify a config file to use with the `--config` CLI opt
vite --config my-config.js
```

::: tip BUNDLING THE CONFIG
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.
:::

## Config Intellisense

Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints:
Expand Down
13 changes: 12 additions & 1 deletion docs/config/preview-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ See [`server.host`](./server-options#server-host) for more details.

:::

## preview.allowedHosts

- **Type:** `string | true`
- **Default:** [`server.allowedHosts`](./server-options#server-allowedhosts)

The hostnames that Vite is allowed to respond to.

See [`server.allowedHosts`](./server-options#server-allowedhosts) for more details.

## preview.port

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

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.
Configure CORS for the preview server.

See [`server.cors`](./server-options#server-cors) for more details.

## preview.headers

Expand Down
23 changes: 22 additions & 1 deletion docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ See [the WSL document](https://learn.microsoft.com/en-us/windows/wsl/networking#

:::

## server.allowedHosts

- **Type:** `string[] | true`
- **Default:** `[]`

The hostnames that Vite is allowed to respond to.
`localhost` and domains under `.localhost` and all IP addresses are allowed by default.
When using HTTPS, this check is skipped.

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`.

If set to `true`, the server is allowed to respond to requests for any hosts.
This is not recommended as it will be vulnerable to DNS rebinding attacks.

## server.port

- **Type:** `number`
Expand Down Expand Up @@ -147,8 +161,15 @@ export default defineConfig({
## server.cors

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

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.
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.

:::warning

We recommend setting a specific value rather than `true` to avoid exposing the source code to untrusted origins.

:::

## server.headers

Expand Down
5 changes: 5 additions & 0 deletions docs/guide/api-environment-frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ The `runner` is evaluated eagerly when it's accessed for the first time. Beware
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.

```js
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { createServer } from 'vite'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const server = await createServer({
server: { middlewareMode: true },
appType: 'custom',
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/api-environment-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,28 +304,28 @@ function createWorkerEnvironment(name, config, context) {
const handlerToWorkerListener = new WeakMap()

const workerHotChannel = {
send: (data) => w.postMessage(data),
send: (data) => worker.postMessage(data),
on: (event, handler) => {
if (event === 'connection') return

const listener = (value) => {
if (value.type === 'custom' && value.event === event) {
const client = {
send(payload) {
w.postMessage(payload)
worker.postMessage(payload)
},
}
handler(value.data, client)
}
}
handlerToWorkerListener.set(handler, listener)
w.on('message', listener)
worker.on('message', listener)
},
off: (event, handler) => {
if (event === 'connection') return
const listener = handlerToWorkerListener.get(handler)
if (listener) {
w.off('message', listener)
worker.off('message', listener)
handlerToWorkerListener.delete(handler)
}
},
Expand Down
6 changes: 6 additions & 0 deletions docs/guide/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ If you need a custom integration, you can follow the steps in this guide to conf
import { defineConfig } from 'vite'
// ---cut---
export default defineConfig({
server: {
cors: {
// the origin you will be accessing via browser
origin: 'http://my-backend.example.com',
},
},
build: {
// generate .vite/manifest.json in outDir
manifest: true,
Expand Down
24 changes: 19 additions & 5 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ When it is time to deploy your app for production, simply run the `vite build` c

## Browser Compatibility

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):
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:

- Chrome >=87
- Firefox >=78
- Safari >=14
- Edge >=88

You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`.
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):

- Chrome >=64
- Firefox >=67
- Safari >=11.1
- Edge >=79

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.

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

```js twoslash [vite.config.js]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
build: {
rollupOptions: {
Expand All @@ -134,9 +142,12 @@ When it is time to bundle your library for distribution, use the [`build.lib` co
::: code-group
```js twoslash [vite.config.js (single entry)]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
build: {
lib: {
Expand All @@ -162,9 +173,12 @@ export default defineConfig({
```
```js twoslash [vite.config.js (multiple entries)]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
build: {
lib: {
Expand Down
Loading

0 comments on commit d00ce43

Please sign in to comment.