Skip to content

Commit 80bd394

Browse files
authored
release: v2.7.13
2 parents e046a48 + 1af1a1d commit 80bd394

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

config/index.md

+48-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export default {
2323
vite --config my-config.js
2424
```
2525

26+
注意,Vite 会替换 `__filename``__dirname` 以及 `import.meta.url`。如果使用这些名称作为变量名可能会导致代码报错:
27+
28+
```js
29+
const __filename = "value"
30+
// will be transformed to
31+
const "path/vite.config.js" = "value"
32+
```
33+
2634
### 配置智能提示 {#config-intellisense}
2735

2836
因为 Vite 本身附带 Typescript 类型,所以你可以通过 IDE 和 jsdoc 的配合来实现智能提示:
@@ -131,9 +139,21 @@ export default defineConfig(async ({ command, mode }) => {
131139

132140
例如,`process.env.FOO``__APP_VERSION__` 就非常适合。但 `process``global` 不应使用此选项。变量相关应使用 shim 或 polyfill 代替。
133141

142+
::: tip NOTE
143+
对于使用 TypeScript 的开发者来说,请确保在 `env.d.ts``vite-env.d.ts` 文件中添加类型声明,以获得类型检查以及代码提示。
144+
145+
Example:
146+
147+
```ts
148+
// vite-env.d.ts
149+
declare const __APP_VERSION__: string
150+
```
151+
152+
:::
153+
134154
### plugins {#plugins}
135155
136-
- **类型:** ` (Plugin | Plugin[])[]`
156+
- **类型:** `(Plugin | Plugin[])[]`
137157
138158
需要用到的插件数组。Falsy 虚值的插件将被忽略,插件数组将被扁平化(flatten)。查看 [插件 API](/guide/api-plugin) 获取 Vite 插件的更多细节。
139159
@@ -153,14 +173,14 @@ export default defineConfig(async ({ command, mode }) => {
153173
- **类型:** `string`
154174
- **默认:** `"node_modules/.vite"`
155175
156-
存储缓存文件的目录。此目录下会存储预打包的依赖项或 vite 生成的某些缓存文件,使用缓存可以提高性能。如需重新生成缓存文件,你可以使用 `--force` 命令行选项或手动删除目录。此选项的值可以是文件的绝对路径,也可以是以项目根目录为基准的相对路径。
176+
存储缓存文件的目录。此目录下会存储预打包的依赖项或 vite 生成的某些缓存文件,使用缓存可以提高性能。如需重新生成缓存文件,你可以使用 `--force` 命令行选项或手动删除目录。此选项的值可以是文件的绝对路径,也可以是以项目根目录为基准的相对路径。当没有检测到 package.json 时,则默认为 `.vite`
157177
158178
### resolve.alias {#resolve-alias}
159179
160180
- **类型:**
161-
`Record<string, string> | Array<{ find: string | RegExp, replacement: string }>`
181+
`Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`
162182
163-
将会被传递到 `@rollup/plugin-alias` 作为 [entries 的选项](https://github.com/rollup/plugins/tree/master/packages/alias#entries)。也可以是一个对象,或一个 `{ find, replacement }` 的数组。
183+
将会被传递到 `@rollup/plugin-alias` 作为 [entries 的选项](https://github.com/rollup/plugins/tree/master/packages/alias#entries)。也可以是一个对象,或一个 `{ find, replacement, customResolver }` 的数组。
164184
165185
当使用文件系统路径的别名时,请始终使用绝对路径。相对路径的别名值会原封不动地被使用,因此无法被正常解析。
166186
@@ -770,6 +790,8 @@ export default defineConfig({
770790

771791
设置为 `false` 可以禁用最小化混淆,或是用来指定使用哪种混淆器。默认为 [Esbuild](https://github.com/evanw/esbuild),它比 terser 快 20-40 倍,压缩率只差 1%-2%。[Benchmarks](https://github.com/privatenumber/minification-benchmarks)
772792

793+
注意,在 lib 模式下使用 `'es'` 时,`build.minify` 选项将失效。
794+
773795
### build.terserOptions {#build-terseroptions}
774796

775797
- **类型:** `TerserOptions`
@@ -826,7 +848,7 @@ export default defineConfig({
826848
### preview.port {#preview-port}
827849

828850
- **类型:** `number`
829-
- **默认:** `5000`
851+
- **默认:** `4173`
830852

831853
指定开发服务器端口。注意,如果设置的端口已被使用,Vite 将自动尝试下一个可用端口,所以这可能不是最终监听的服务器端口。
832854

@@ -957,3 +979,24 @@ SSR 选项可能会在未来版本中进行调整。
957979
- **默认:** `node`
958980

959981
SSR 服务器的构建目标。
982+
983+
## Worker 选项 {#worker-options}
984+
985+
### worker.format
986+
987+
- **类型:** `'es' | 'iife'`
988+
- **默认:** `iife`
989+
990+
worker bundle 的输出类型。
991+
992+
### worker.plugins
993+
994+
- **类型:** [`(Plugin | Plugin[])[]`](#plugins)
995+
996+
适用于 worker bundle 的 Vite 插件。
997+
998+
### worker.rollupOptions
999+
1000+
- **类型:** [`RollupOptions`](https://rollupjs.org/guide/en/#big-list-of-options)
1001+
1002+
用于构建 worker bundle 的 Rollup 配置项。

guide/env-and-mode.md

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ Vite 使用 [dotenv](https://github.com/motdotla/dotenv) 从你的 [环境目录
3333
.env.[mode].local # 只在指定模式下加载,但会被 git 忽略
3434
```
3535

36+
:::tip 环境加载优先级
37+
38+
一份用于指定模式的文件(例如 `.env.production`)会比通用形式的优先级更高(例如 `.env`)。
39+
40+
另外,Vite 执行时已经存在的环境变量有最高的优先级,不会被 `.env` 类文件覆盖。
41+
42+
`.env` 类文件会在 Vite 启动一开始时被加载,而改动会在重启服务器后生效。
43+
:::
44+
3645
加载的环境变量也会通过 `import.meta.env` 暴露给客户端源码。
3746

3847
为了防止意外地将一些环境变量泄漏到客户端,只有以 `VITE_` 为前缀的变量才会暴露给经过 vite 处理的代码。例如下面这个文件中:

guide/features.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Vite 仅执行 `.ts` 文件的转译工作,并 **不** 执行任何类型检
3434

3535
Vite 使用 [esbuild](https://github.com/evanw/esbuild) 将 TypeScript 转译到 JavaScript,约是 `tsc` 速度的 20~30 倍,同时 HMR 更新反映到浏览器的时间小于 50ms。
3636

37+
使用 [仅含类型的导入和导出](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) 形式的语法可以避免潜在的 “仅含类型的导入被不正确打包” 的问题,写法示例如下:
38+
39+
```ts
40+
import type { T } from 'only/types'
41+
export type { T }
42+
```
43+
3744
### TypeScript 编译器选项 {#typescript-compiler-options}
3845

3946
`tsconfig.json``compilerOptions` 下的一些配置项需要特别注意。
@@ -63,6 +70,7 @@ Vite 使用 [esbuild](https://github.com/evanw/esbuild) 将 TypeScript 转译到
6370

6471
- [`extends`](https://www.typescriptlang.org/tsconfig#extends)
6572
- [`importsNotUsedAsValues`](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues)
73+
- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports)
6674
- [`jsxFactory`](https://www.typescriptlang.org/tsconfig#jsxFactory)
6775
- [`jsxFragmentFactory`](https://www.typescriptlang.org/tsconfig#jsxFragmentFactory)
6876

@@ -183,13 +191,13 @@ document.getElementById('foo').className = applyColor
183191

184192
```bash
185193
# .scss and .sass
186-
npm install -D sass
194+
npm add -D sass
187195

188196
# .less
189-
npm install -D less
197+
npm add -D less
190198

191199
# .styl and .stylus
192-
npm install -D stylus
200+
npm add -D stylus
193201
```
194202

195203
如果是用的是单文件组件,可以通过 `<style lang="sass">`(或其他预处理器)自动开启。

guide/index.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Vite 意在提供开箱即用的配置,同时它的 [插件 API](./api-plugin)
3838
## 搭建第一个 Vite 项目 {#scaffolding-your-first-vite-project}
3939

4040
::: tip 兼容性注意
41-
Vite 需要 [Node.js](https://nodejs.org/en/) 版本 >= 12.0.0。
41+
Vite 需要 [Node.js](https://nodejs.org/en/) 版本 >= 12.0.0。然而,有些模板需要依赖更高的 Node 版本才能正常运行,当你的包管理器发出警告时,请注意升级你的 Node 版本。
4242
:::
4343

4444
使用 NPM:
4545

4646
```bash
47-
$ npm init vite@latest
47+
$ npm create vite@latest
4848
```
4949

5050
使用 Yarn:
@@ -65,10 +65,10 @@ $ pnpm create vite
6565

6666
```bash
6767
# npm 6.x
68-
npm init vite@latest my-vue-app --template vue
68+
npm create vite@latest my-vue-app --template vue
6969

70-
# npm 7+, 需要额外的双横线:
71-
npm init vite@latest my-vue-app -- --template vue
70+
# npm 7+, extra double-dash is needed:
71+
npm create vite@latest my-vue-app -- --template vue
7272

7373
# yarn
7474
yarn create vite my-vue-app --template vue

guide/using-plugins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vite 可以使用插件进行扩展,这得益于 Rollup 优秀的插件接口
77
若要使用一个插件,需要将它添加到项目的 `devDependencies` 并在 `vite.config.js` 配置文件中的 `plugins` 数组中引入它。例如,要想为传统浏览器提供支持,可以按下面这样使用官方插件 [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy)
88

99
```
10-
$ npm i -D @vitejs/plugin-legacy
10+
$ npm add -D @vitejs/plugin-legacy
1111
```
1212

1313
```js

0 commit comments

Comments
 (0)