Skip to content

Commit 3b83fbf

Browse files
authored
Merge pull request #1400 from vitejs/dev
d2m
2 parents ff14007 + 90c694e commit 3b83fbf

File tree

4 files changed

+94
-30
lines changed

4 files changed

+94
-30
lines changed

config/build-options.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,71 @@ export default defineConfig({
185185
})
186186
```
187187

188+
## build.license {#build-license}
189+
190+
- **类型:** `boolean | { fileName?: string }`
191+
- **默认:** `false`
192+
193+
当设置为 `true` 时,构建过程将生成一个 `.vite/license.md` 文件,其中包含所有打包依赖项的许可证信息。该文件可以被托管,用于展示和确认应用程序所使用的依赖项。当传入 `fileName` 参数时,它将被用作相对于 `outDir` 的许可证文件名。示例输出可能如下所示:
194+
195+
```md
196+
# Licenses
197+
198+
The app bundles dependencies which contain the following licenses:
199+
200+
## dep-1 - 1.2.3 (CC0-1.0)
201+
202+
CC0 1.0 Universal
203+
204+
...
205+
206+
## dep-2 - 4.5.6 (MIT)
207+
208+
MIT License
209+
210+
...
211+
```
212+
213+
如果 `fileName``.json` 结尾,则会生成原始的 JSON 元数据,可用于进一步处理。例如:
214+
215+
```json
216+
[
217+
{
218+
"name": "dep-1",
219+
"version": "1.2.3",
220+
"identifier": "CC0-1.0",
221+
"text": "CC0 1.0 Universal\n\n..."
222+
},
223+
{
224+
"name": "dep-2",
225+
"version": "4.5.6",
226+
"identifier": "MIT",
227+
"text": "MIT License\n\n..."
228+
}
229+
]
230+
```
231+
232+
::: tip
233+
如果你希望在构建后的代码中引用许可证文件,可以使用 `build.rollupOptions.output.banner` 在文件顶部注入注释。例如:
234+
235+
```js twoslash [vite.config.js]
236+
import { defineConfig } from 'vite'
237+
238+
export default defineConfig({
239+
build: {
240+
license: true,
241+
rollupOptions: {
242+
output: {
243+
banner:
244+
'/* See licenses of bundled dependencies at https://example.com/license.md */',
245+
},
246+
},
247+
},
248+
})
249+
```
250+
251+
:::
252+
188253
## build.manifest {#build-manifest}
189254

190255
- **类型:** `boolean | string`

config/dep-optimization-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
默认情况下,Vite 会抓取你的 `index.html` 来检测需要预构建的依赖项(忽略了`node_modules``build.outDir``__tests__``coverage`)。如果指定了 `build.rollupOptions.input`,Vite 将转而去抓取这些入口点。
1212

13-
如果这两者都不合你意,则可以使用此选项指定自定义条目——该值需要遵循 [tinyglobby 模式](https://github.com/SuperchupuDev/tinyglobby) ,或者是相对于 Vite 项目根目录的匹配模式数组。当显式声明了 `optimizeDeps.entries` 时默认只有 `node_modules``build.outDir` 文件夹会被忽略。如果还需忽略其他文件夹,你可以在模式列表中使用以 `!` 为前缀的、用来匹配忽略项的模式。对于明确包含字符串 `node_modules` 的模式,不会忽略 `node_modules`
13+
如果这两者都不合你意,则可以使用此选项指定自定义条目——该值需要遵循 [tinyglobby 模式](https://superchupu.dev/tinyglobby/comparison) ,或者是相对于 Vite 项目根目录的匹配模式数组。当显式声明了 `optimizeDeps.entries` 时默认只有 `node_modules``build.outDir` 文件夹会被忽略。如果还需忽略其他文件夹,你可以在模式列表中使用以 `!` 为前缀的、用来匹配忽略项的模式。对于明确包含字符串 `node_modules` 的模式,不会忽略 `node_modules`
1414

1515
## optimizeDeps.exclude <NonInheritBadge /> {#optimizedeps-exclude}
1616

config/server-options.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ Vite允许响应的主机名。
9292

9393
启用 TLS + HTTP/2。该值是传递给 `https.createServer()`[options 对象](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener)
9494

95-
请注意,仅当同时使用 [`server.proxy` 选项](#server-proxy) 时,才会降级为 TLS。
96-
9795
需要一个合法可用的证书。对基本使用的配置需求来说,你可以添加 [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl) 到项目插件中,它会自动创建和缓存一个自签名的证书。但我们推荐你创建和使用你自己的证书。
9896

9997
## server.open {#server-open}
@@ -233,7 +231,7 @@ Direct websocket connection fallback. Check out https://vite.dev/config/server-o
233231

234232
提前转换和缓存文件以进行预热。可以在服务器启动时提高初始页面加载速度,并防止转换瀑布。
235233

236-
`clientFiles` 是仅在客户端使用的文件,而 `ssrFiles` 是仅在服务端渲染中使用的文件。它们接受相对于 `root` 的文件路径数组或 [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) 模式
234+
`clientFiles` 是仅在客户端使用的文件,而 `ssrFiles` 是仅在服务端渲染中使用的文件。它们接受相对于 `root` 的文件路径数组或 [`tinyglobby` 模式](https://superchupu.dev/tinyglobby/comparison)
237235

238236
请确保只添加经常使用的文件,以免在启动时过载 Vite 开发服务器。
239237

guide/features.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ HTML 文件位于 Vite 项目的[最前端和中心](/guide/#index-html-and-proj
196196
- 或仅当 `property` 属性匹配以下值时:`og:image``og:image:url``og:image:secure_url``og:audio``og:audio:secure_url``og:video`,或 `og:video:secure_url`
197197

198198
```html {4-5,8-9}
199-
<!doctype html>
199+
<!DOCTYPE html>
200200
<html>
201201
<head>
202202
<link rel="icon" href="/favicon.ico" />
@@ -237,8 +237,8 @@ import { defineConfig } from 'vite'
237237
export default defineConfig({
238238
esbuild: {
239239
jsxFactory: 'h',
240-
jsxFragment: 'Fragment',
241-
},
240+
jsxFragment: 'Fragment'
241+
}
242242
})
243243
```
244244

@@ -251,8 +251,8 @@ import { defineConfig } from 'vite'
251251

252252
export default defineConfig({
253253
esbuild: {
254-
jsxInject: `import React from 'react'`,
255-
},
254+
jsxInject: `import React from 'react'`
255+
}
256256
})
257257
```
258258

@@ -427,7 +427,7 @@ const modules = import.meta.glob('./dir/*.js')
427427
// vite 生成的代码
428428
const modules = {
429429
'./dir/bar.js': () => import('./dir/bar.js'),
430-
'./dir/foo.js': () => import('./dir/foo.js'),
430+
'./dir/foo.js': () => import('./dir/foo.js')
431431
}
432432
```
433433

@@ -457,7 +457,7 @@ import * as __vite_glob_0_0 from './dir/bar.js'
457457
import * as __vite_glob_0_1 from './dir/foo.js'
458458
const modules = {
459459
'./dir/bar.js': __vite_glob_0_0,
460-
'./dir/foo.js': __vite_glob_0_1,
460+
'./dir/foo.js': __vite_glob_0_1
461461
}
462462
```
463463

@@ -484,7 +484,7 @@ const modules = import.meta.glob(['./dir/*.js', '!**/bar.js'])
484484
```js
485485
// vite 生成的代码
486486
const modules = {
487-
'./dir/foo.js': () => import('./dir/foo.js'),
487+
'./dir/foo.js': () => import('./dir/foo.js')
488488
}
489489
```
490490

@@ -502,7 +502,7 @@ const modules = import.meta.glob('./dir/*.js', { import: 'setup' })
502502
// vite 生成的代码
503503
const modules = {
504504
'./dir/bar.js': () => import('./dir/bar.js').then((m) => m.setup),
505-
'./dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup),
505+
'./dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup)
506506
}
507507
```
508508

@@ -513,7 +513,7 @@ import 'vite/client'
513513
// ---cut---
514514
const modules = import.meta.glob('./dir/*.js', {
515515
import: 'setup',
516-
eager: true,
516+
eager: true
517517
})
518518
```
519519

@@ -523,7 +523,7 @@ import { setup as __vite_glob_0_0 } from './dir/bar.js'
523523
import { setup as __vite_glob_0_1 } from './dir/foo.js'
524524
const modules = {
525525
'./dir/bar.js': __vite_glob_0_0,
526-
'./dir/foo.js': __vite_glob_0_1,
526+
'./dir/foo.js': __vite_glob_0_1
527527
}
528528
```
529529

@@ -534,7 +534,7 @@ import 'vite/client'
534534
// ---cut---
535535
const modules = import.meta.glob('./dir/*.js', {
536536
import: 'default',
537-
eager: true,
537+
eager: true
538538
})
539539
```
540540

@@ -544,7 +544,7 @@ import { default as __vite_glob_0_0 } from './dir/bar.js'
544544
import { default as __vite_glob_0_1 } from './dir/foo.js'
545545
const modules = {
546546
'./dir/bar.js': __vite_glob_0_0,
547-
'./dir/foo.js': __vite_glob_0_1,
547+
'./dir/foo.js': __vite_glob_0_1
548548
}
549549
```
550550

@@ -557,23 +557,23 @@ import 'vite/client'
557557
// ---cut---
558558
const moduleStrings = import.meta.glob('./dir/*.svg', {
559559
query: '?raw',
560-
import: 'default',
560+
import: 'default'
561561
})
562562
const moduleUrls = import.meta.glob('./dir/*.svg', {
563563
query: '?url',
564-
import: 'default',
564+
import: 'default'
565565
})
566566
```
567567

568568
```ts
569569
// vite 生成的代码
570570
const moduleStrings = {
571571
'./dir/bar.svg': () => import('./dir/bar.svg?raw').then((m) => m['default']),
572-
'./dir/foo.svg': () => import('./dir/foo.svg?raw').then((m) => m['default']),
572+
'./dir/foo.svg': () => import('./dir/foo.svg?raw').then((m) => m['default'])
573573
}
574574
const moduleUrls = {
575575
'./dir/bar.svg': () => import('./dir/bar.svg?url').then((m) => m['default']),
576-
'./dir/foo.svg': () => import('./dir/foo.svg?url').then((m) => m['default']),
576+
'./dir/foo.svg': () => import('./dir/foo.svg?url').then((m) => m['default'])
577577
}
578578
```
579579

@@ -583,7 +583,7 @@ const moduleUrls = {
583583
import 'vite/client'
584584
// ---cut---
585585
const modules = import.meta.glob('./dir/*.js', {
586-
query: { foo: 'bar', bar: true },
586+
query: { foo: 'bar', bar: true }
587587
})
588588
```
589589

@@ -595,15 +595,15 @@ const modules = import.meta.glob('./dir/*.js', {
595595
import 'vite/client'
596596
// ---cut---
597597
const modulesWithBase = import.meta.glob('./**/*.js', {
598-
base: './base',
598+
base: './base'
599599
})
600600
```
601601

602602
```ts
603603
// code produced by vite:
604604
const modulesWithBase = {
605605
'./dir/foo.js': () => import('./base/dir/foo.js'),
606-
'./dir/bar.js': () => import('./base/dir/bar.js'),
606+
'./dir/bar.js': () => import('./base/dir/bar.js')
607607
}
608608
```
609609

@@ -619,7 +619,7 @@ const modulesWithBase = {
619619

620620
- 这只是一个 Vite 独有的功能而不是一个 Web 或 ES 标准
621621
- 该 Glob 模式会被当成导入标识符:必须是相对路径(以 `./` 开头)或绝对路径(以 `/` 开头,相对于项目根目录解析)或一个别名路径(请看 [`resolve.alias` 选项](/config/shared-options.md#resolve-alias))。
622-
- Glob 匹配是使用 [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) 来实现的 —— 阅读它的文档来查阅 [支持的 Glob 模式](https://github.com/mrmlnc/fast-glob#pattern-syntax)
622+
- Glob 匹配是使用 [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) 来实现的 —— 阅读它的文档来查阅 [支持的 Glob 模式](https://superchupu.dev/tinyglobby/comparison)
623623
- 你还需注意,所有 `import.meta.glob` 的参数都必须以字面量传入。你 **** 可以在其中使用变量或表达式。
624624

625625
## 动态导入 {#dynamic-import}
@@ -657,8 +657,8 @@ init({
657657
imports: {
658658
someFunc: () => {
659659
/* ... */
660-
},
661-
},
660+
}
661+
}
662662
}).then(() => {
663663
/* ... */
664664
})
@@ -682,8 +682,9 @@ import wasmUrl from 'foo.wasm?url'
682682

683683
const main = async () => {
684684
const responsePromise = fetch(wasmUrl)
685-
const { module, instance } =
686-
await WebAssembly.instantiateStreaming(responsePromise)
685+
const { module, instance } = await WebAssembly.instantiateStreaming(
686+
responsePromise
687+
)
687688
/* ... */
688689
}
689690

@@ -729,7 +730,7 @@ worker 构造函数会接受可以用来创建 “模块” worker 的选项:
729730

730731
```ts
731732
const worker = new Worker(new URL('./worker.js', import.meta.url), {
732-
type: 'module',
733+
type: 'module'
733734
})
734735
```
735736

0 commit comments

Comments
 (0)