Skip to content

Commit e5bdb99

Browse files
authored
Merge pull request #807 from vitejs/dev
docs(cn): update with mainstream
2 parents 969230a + f8fc696 commit e5bdb99

File tree

7 files changed

+168
-9
lines changed

7 files changed

+168
-9
lines changed

.vitepress/theme/components/AsideSponsors.vue

+63
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,68 @@ const sponsors = computed(() => {
1818
</script>
1919

2020
<template>
21+
<a class="viteconf" href="https://viteconf.org/23" target="_blank">
22+
<img width="22" height="22" src="/viteconf.svg" />
23+
<span>
24+
<p class="extra-info">Free Online Conference</p>
25+
<p class="heading">ViteConf 23 - Oct 5</p>
26+
<p class="extra-info">Get your ticket now!</p>
27+
</span>
28+
</a>
2129
<VPDocAsideSponsors v-if="data" :data="sponsors" />
2230
</template>
31+
32+
<style>
33+
.viteconf {
34+
margin-top: 1rem;
35+
margin-bottom: 1rem;
36+
border-radius: 14px;
37+
padding-left: 2.5rem;
38+
padding-top: 0.4rem;
39+
padding-bottom: 0.4rem;
40+
position: relative;
41+
font-size: 0.9rem;
42+
font-weight: 700;
43+
line-height: 1.1rem;
44+
display: flex;
45+
align-items: center;
46+
justify-content: center;
47+
gap: 0.75rem;
48+
background-color: var(--vp-c-bg-alt);
49+
border: 2px solid var(--vp-c-bg-alt);
50+
transition: border-color 0.5s;
51+
}
52+
.viteconf:hover {
53+
border: 2px solid var(--vp-c-brand-light);
54+
}
55+
.viteconf img {
56+
position: absolute;
57+
left: 1.5rem;
58+
transition: transform 0.5s;
59+
transform: scale(1.25);
60+
}
61+
.viteconf:hover img {
62+
transform: scale(1.75);
63+
}
64+
.viteconf .heading {
65+
background-image: linear-gradient(
66+
120deg,
67+
#b047ff 16%,
68+
var(--vp-c-brand-lighter),
69+
var(--vp-c-brand-lighter)
70+
);
71+
background-clip: text;
72+
-webkit-background-clip: text;
73+
-webkit-text-fill-color: transparent;
74+
}
75+
.viteconf .extra-info {
76+
color: var(--vp-c-text-1);
77+
opacity: 0;
78+
font-size: 0.7rem;
79+
padding-left: 0.1rem;
80+
transition: opacity 0.5s;
81+
}
82+
.viteconf:hover .extra-info {
83+
opacity: 0.9;
84+
}
85+
</style>

guide/cli.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ vite [root]
1414

1515
#### 选项 {#options}
1616

17-
| 选项 | |
18-
| ------------------------ | ------------------------------------------- |
17+
| 选项 | |
18+
| ------------------------ | -------------------------------------------------------------------------------------- |
1919
| `--host [host]` | 指定主机名称 (`string`) |
2020
| `--port <port>` | 指定端口 (`number`) |
2121
| `--https` | 使用 TLS + HTTP/2 (`boolean`) |
@@ -27,6 +27,7 @@ vite [root]
2727
| `--base <path>` | 公共基础路径(默认为:`/`)(`string`) |
2828
| `-l, --logLevel <level>` | Info \| warn \| error \| silent (`string`) |
2929
| `--clearScreen` | 允许或禁用打印日志时清除屏幕 (`boolean`) |
30+
| `--profile` | 启动内置的 Node.js 调试器(查看 [性能瓶颈](/guide/troubleshooting#performance-bottlenecks)|
3031
| `-d, --debug [feat]` | 显示调试日志 (`string \| boolean`) |
3132
| `-f, --filter <filter>` | 过滤调试日志 (`string`) |
3233
| `-m, --mode <mode>` | 设置环境模式 (`string`) |
@@ -65,6 +66,7 @@ vite build [root]
6566
| `--base <path>` | 公共基础路径(默认为:`/`)(`string`) |
6667
| `-l, --logLevel <level>` | Info \| warn \| error \| silent (`string`) |
6768
| `--clearScreen` | 允许或禁用打印日志时清除屏幕 (`boolean`) |
69+
| `--profile` | 启动内置的 Node.js 调试器(查看 [性能瓶颈](/guide/troubleshooting#performance-bottlenecks)|
6870
| `-d, --debug [feat]` | 显示调试日志 (`string \| boolean`) |
6971
| `-f, --filter <filter>` | 过滤调试日志 (`string`) |
7072
| `-m, --mode <mode>` | 设置环境模式 (`string`) |

guide/features.md

+47-5
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ const module = await import(`./dir/${file}.js`)
500500

501501
## WebAssembly {#webassembly}
502502

503-
预编译的 `.wasm` 文件可以通过 `?init` 来导入。默认导出一个初始化函数,返回值为所导出 wasm 实例对象的 Promise:
503+
预编译的 `.wasm` 文件可以通过 `?init` 来导入。
504+
默认导出一个初始化函数,返回值为所导出 [`WebAssembly.Instance`](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Instance) 实例对象的 Promise:
504505

505506
```js
506507
import init from './example.wasm?init'
@@ -510,7 +511,7 @@ init().then((instance) => {
510511
})
511512
```
512513

513-
`init` 函数还可以将传递给 `WebAssembly.instantiate` 的导入对象作为其第二个参数:
514+
`init` 函数还可以将传递给 [`WebAssembly.instantiate`](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/instantiate) 的导入对象作为其第二个参数:
514515

515516
```js
516517
init({
@@ -524,13 +525,54 @@ init({
524525
})
525526
```
526527

527-
在生产构建当中,体积小于 `assetInlineLimit``.wasm` 文件将会被内联为 base64 字符串。否则,它们将作为资源复制到 `dist` 目录中,并按需获取。
528+
在生产构建当中,体积小于 `assetInlineLimit``.wasm` 文件将会被内联为 base64 字符串。否则,它们将被视为 [静态资源](./assets) ,并按需获取。
528529

529-
::: warning
530+
::: tip 注意
530531
[对 WebAssembly 的 ES 模块集成提案](https://github.com/WebAssembly/esm-integration) 尚未支持。
531532
请使用 [`vite-plugin-wasm`](https://github.com/Menci/vite-plugin-wasm) 或其他社区上的插件来处理。
532533
:::
533534

535+
### 访问 WebAssembly 模块 {#accessing-the-webassembly-module}
536+
537+
如果需要访问 `Module` 对象,例如将它多次实例化,可以使用 [显式 URL 引入](./assets#explicit-url-imports) 来解析资源,然后执行实例化:
538+
539+
```js
540+
import wasmUrl from 'foo.wasm?url'
541+
542+
const main = async () => {
543+
const responsePromise = fetch(wasmUrl)
544+
const { module, instance } = await WebAssembly.instantiateStreaming(
545+
responsePromise,
546+
)
547+
/* ... */
548+
}
549+
550+
main()
551+
```
552+
553+
### 在 Node.js 中获取模块 {#fetching-the-module-in-node-js}
554+
555+
在 SSR 中,作为 `?init` 导入的 `fetch()` 可能会失败,导致 `TypeError: Invalid URL` 报错。
556+
请参见问题 [在 SSR 中支持 wasm](https://github.com/vitejs/vite/issues/8882)
557+
558+
以下是一种替代方案,假设项目根目录在当前目录:
559+
560+
```js
561+
import wasmUrl from 'foo.wasm?url'
562+
import { readFile } from 'node:fs/promises'
563+
564+
const main = async () => {
565+
const resolvedUrl = (await import('./test/boot.test.wasm?url')).default
566+
const buffer = await readFile('.' + resolvedUrl)
567+
const { instance } = await WebAssembly.instantiate(buffer, {
568+
/* ... */
569+
})
570+
/* ... */
571+
}
572+
573+
main()
574+
```
575+
534576
## Web Workers {#web-workers}
535577

536578
### 通过构造器导入 {#import-with-constructors}
@@ -559,7 +601,7 @@ import MyWorker from './worker?worker'
559601
const worker = new MyWorker()
560602
```
561603

562-
Worker 脚本也可以使用 ESM `import` 语句来替代 `importScripts()` —— **注意**,在开发过程中,这依赖于[浏览器原生支持](https://caniuse.com/?search=module%20worker)(目前在 Firefox 中不支持),而在生产版本中,它已经被编译掉了
604+
这个 worker 脚本也可以使用 ESM `import` 语句而不是 `importScripts()`**注意**:在开发时,这依赖于 [浏览器原生支持](https://caniuse.com/?search=module%20worker),但是在生产构建中,它会被编译掉
563605

564606
默认情况下,worker 脚本将在生产构建中编译成单独的 chunk。如果你想将 worker 内联为 base64 字符串,请添加 `inline` 查询参数:
565607

guide/static-deploy.md

+4
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,7 @@ $ npx wrangler pages publish dist
337337
## Flightcontrol
338338

339339
使用 [Flightcontrol](https://www.flightcontrol.dev/?ref=docs-vite) 部署静态站点,可以按照 [说明](https://www.flightcontrol.dev/docs/reference/examples/vite?ref=docs-vite) 进行操作。
340+
341+
## AWS Amplify 部署 {#aws-amplify-hoisting}
342+
343+
使用 [AWS Amplify 部署](https://aws.amazon.com/amplify/hosting/) 部署静态站点,可以按照 [说明](https://docs.amplify.aws/guides/hosting/vite/q/platform/js/) 进行操作。

guide/troubleshooting.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,31 @@ import './Foo.js' // 应该为 './foo.js'
144144

145145
在 Vite 中通过一个哈希值来决定优化后的依赖项是否有效,这个值取决于包锁定的内容、应用于依赖项的补丁以及 Vite 配置文件中影响 node_modules 打包的选项。这意味着,当使用像 [npm overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) 这样的功能覆盖依赖项时,Vite 将检测到,并在下一次服务器启动时重新打包您的依赖项。当您使用像 [npm link](https://docs.npmjs.com/cli/v9/commands/npm-link) 这样的功能时,Vite 不会使依赖项无效。如果您链接或取消链接一个依赖项,那么您需要使用 `vite --force` 在下一次服务器启动时强制重新预构建。我们建议使用 overrides,它们现在被每个包管理器所支持(还可以参见 [pnpm overrides](https://pnpm.io/package_json#pnpmoverrides)[yarn resolutions](https://yarnpkg.com/configuration/manifest/#resolutions))。
146146

147+
## 性能瓶颈 {#performance-bottlenecks}
148+
149+
如果你遇到应用程序性能瓶颈导致加载缓慢,可以在启动 Vite 开发服务器或在构建应用程序时使用内置的 Node.js 调试器来创建 CPU 性能分析文件:
150+
151+
::: code-group
152+
153+
```bash [dev server]
154+
vite --profile --open
155+
```
156+
157+
```bash [build]
158+
vite build --profile
159+
```
160+
161+
:::
162+
163+
::: tip Vite 开发服务器
164+
一旦应用程序在浏览器中打开,请等待其完成加载,然后返回终端并按下 `p` 键(将停止 Node.js 调试器),然后按下 `q` 键停止开发服务器。
165+
:::
166+
167+
Node.js 调试器将在根文件夹中生成 `vite-profile-0.cpuprofile` 文件,前往 https://www.speedscope.app/,点击 `BROWSE` 按钮上传 CPU 性能分析文件以检查结果。
168+
147169
## 其他 {#others}
148170

149-
### Module externalized for browser compatibility {#module-externalized-for-browser-compatibility}
171+
### 为了浏览器兼容性而模块外部化 {#module-externalized-for-browser-compatibility}
150172

151173
当你在浏览器中使用一个 Node.js 模块时,Vite 会输出以下警告:
152174

index.md

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ hero:
2121
- theme: alt
2222
text: 在 GitHub 上查看
2323
link: https://github.com/vitejs/vite
24+
- theme: brand
25+
text: 🎉 ViteConf 23!
26+
link: https://viteconf.org/23
2427

2528
features:
2629
- icon: 💡

0 commit comments

Comments
 (0)