@@ -367,7 +367,7 @@ export default async ({ command, mode }) => {
367
367
368
368
- ** 类型:** ` boolean | string `
369
369
370
- 在开发服务器启动时自动在浏览器中打开应用程序。当此值为字符串时,会被用作 URL 的路径名。
370
+ 在开发服务器启动时自动在浏览器中打开应用程序。当此值为字符串时,会被用作 URL 的路径名。若你想指定喜欢的浏览器打开服务器,你可以设置环境变量 ` process.env.BROWSER ` (例如: ` firefox ` )。查看 [ 这个 ` open ` 包 ] ( https://github.com/sindresorhus/open#app ) 获取更多细节。
371
371
372
372
** 示例:**
373
373
@@ -383,7 +383,7 @@ export default async ({ command, mode }) => {
383
383
384
384
- ** 类型:** ` Record<string, string | ProxyOptions> `
385
385
386
- 为开发服务器配置自定义代理规则。期望接收一个 ` { key: options } ` 对象。如果 key 值以 ` ^ ` 开头,将会被解释为 ` RegExp ` 。
386
+ 为开发服务器配置自定义代理规则。期望接收一个 ` { key: options } ` 对象。如果 key 值以 ` ^ ` 开头,将会被解释为 ` RegExp ` 。` configure ` 可用于访问 proxy 实例。
387
387
388
388
使用 [ ` http-proxy ` ] ( https://github.com/http-party/node-http-proxy ) 。完整选项详见 [ 此处] ( https://github.com/http-party/node-http-proxy#options ) .
389
389
@@ -406,6 +406,14 @@ export default async ({ command, mode }) => {
406
406
target: ' http://jsonplaceholder.typicode.com' ,
407
407
changeOrigin: true ,
408
408
rewrite : (path ) => path .replace (/ ^ \/ fallback/ , ' ' )
409
+ },
410
+ // 使用 proxy 实例
411
+ ' /api' : {
412
+ target: ' http://jsonplaceholder.typicode.com' ,
413
+ changeOrigin: true ,
414
+ configure : (proxy , options ) => {
415
+ // proxy 是 'http-proxy' 的实例
416
+ }),
409
417
}
410
418
}
411
419
}
@@ -437,7 +445,6 @@ export default async ({ command, mode }) => {
437
445
438
446
当使用 ` server.middlewareMode ` 和 ` server.https ` 时,你需将 ` server.hmr.server ` 设置为你 HTTPS 的服务器,这将通过你的服务器来处理 HMR 的安全连接请求。这在使用自签证书的情况下,非常有用。
439
447
440
-
441
448
### server.watch {#server-watch}
442
449
443
450
- ** 类型:** ` object `
@@ -481,7 +488,7 @@ async function createServer() {
481
488
createServer ()
482
489
```
483
490
484
- ### server.fsServe .strict {#server-fsserve -strict}
491
+ ### server.fs .strict {#server-fs -strict}
485
492
486
493
- ** 实验性**
487
494
- ** 类型:** ` boolean `
@@ -494,7 +501,7 @@ createServer()
494
501
- ** 实验性**
495
502
- ** 类型:** ` string `
496
503
497
- 限制哪些文件可以通过 ` /@fs/ ` 路径提供服务。当 ` server.fsServe.strict ` 设置为 true 时,访问这个目录外的文件将会返回 403 结果。
504
+ 限制哪些文件可以通过 ` /@fs/ ` 路径提供服务。当 ` server.fsServe.strict ` 设置为 true 时,访问这个目录列表外的文件将会返回 403 结果。
498
505
499
506
Vite 将会搜索此根目录下潜在工作空间并作默认使用。一个有效的工作空间应符合以下几个条件,否则会默认以 [ 项目 root 目录] ( /guide/#index-html-and-project-root ) 作备选方案。
500
507
@@ -507,9 +514,9 @@ createServer()
507
514
``` js
508
515
export default {
509
516
server: {
510
- fsServe : {
517
+ fs : {
511
518
// 可以为项目根目录的上一级提供服务
512
- root : ' ..'
519
+ allow : [ ' ..' ]
513
520
}
514
521
}
515
522
}
@@ -525,7 +532,10 @@ createServer()
525
532
526
533
设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——` 'modules' ` ,这是指 [ 支持原生 ES 模块的浏览器] ( https://caniuse.com/es6-module ) 。
527
534
528
- 另一个特殊值是 “esnext” —— 即指执行 minify 转换(作最小化压缩)并假设有原生动态导入支持。
535
+ 另一个特殊值是 “esnext” —— 即假设有原生动态导入支持,并且将会转译得尽可能小:
536
+
537
+ - 如果 [ ` build.minify ` ] ( #build-minify ) 选项为 ` 'terser' ` (默认值), ` 'esnext' ` 将会强制降级为 ` 'es2019' ` 。
538
+ - 其他情况下将完全不会执行转译。
529
539
530
540
转换过程将会由 esbuild 执行,并且此值应该是一个合法的 [ esbuild 目标选项] ( https://esbuild.github.io/api/#target ) 。自定义目标也可以是一个 ES 版本(例如:` es2015 ` )、一个浏览器版本(例如:` chrome58 ` )或是多个目标组成的一个数组。
531
541
@@ -584,7 +594,7 @@ createServer()
584
594
585
595
### build.sourcemap {#build-sourcemap}
586
596
587
- - ** 类型:** ` boolean | 'inline' `
597
+ - ** 类型:** ` boolean | 'inline' ` | 'hidden'`
588
598
- ** 默认:** ` false `
589
599
590
600
构建后是否生成 source map 文件。
@@ -601,6 +611,12 @@ createServer()
601
611
602
612
传递给 [ @rollup/plugin-commonjs ] ( https://github.com/rollup/plugins/tree/master/packages/commonjs ) 插件的选项。
603
613
614
+ ### build.dynamicImportVarsOptions {#build-dynamicimportvarsoptions}
615
+
616
+ - ** 类型:** [ ` RollupDynamicImportVarsOptions ` ] ( https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#options )
617
+
618
+ 传递给 [ @rollup/plugin-dynamic-import-vars ] ( https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars ) 的选项。
619
+
604
620
### build.lib {#build-lib}
605
621
606
622
- ** 类型:** ` { entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: string } `
@@ -688,6 +704,10 @@ createServer()
688
704
689
705
在预构建中强制排除的依赖项。
690
706
707
+ :::warning CommonJS
708
+ CommonJS 的依赖不应该排除在优化外。如果一个 ESM 依赖拥有一个嵌套的 CommonJS 依赖,它也不应被排除。
709
+ :::
710
+
691
711
### optimizeDeps.include {#optimizedeps-include}
692
712
693
713
- ** 类型:** ` string[] `
@@ -719,7 +739,7 @@ SSR 选项可能会在未来版本中进行调整。
719
739
720
740
### ssr.noExternal {#ssr-noexternal}
721
741
722
- - ** 类型:** ` string[] `
742
+ - ** 类型:** ` string | RegExp | (string | RegExp) [] `
723
743
724
744
列出的是防止被 SSR 外部化依赖项。
725
745
0 commit comments