Skip to content

Commit 4cfe8bc

Browse files
authored
feat(docs): Add Chinese translation (#54)
Signed-off-by: ajiho <lujiahao@88.com>
1 parent e0956ce commit 4cfe8bc

File tree

14 files changed

+548
-1
lines changed

14 files changed

+548
-1
lines changed

docs/.vitepress/config/en.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from "vitepress";
2+
import pkg from '../../../package.json' with { type: 'json' }
23

34
export const en = defineConfig({
45
lang: "en-US",
@@ -45,7 +46,7 @@ function nav() {
4546
activeMatch: "/reference/",
4647
},
4748
{
48-
text: "0.4.1",
49+
text: pkg.bundlewatch.version,
4950
items: [
5051
{
5152
text: "Release Notes",

docs/.vitepress/config/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { defineConfig } from "vitepress";
22
import { shared } from "./shared.mjs";
33
import { en } from "./en.mjs";
4+
import { zh } from "./zh.mjs";
45

56
const config = {
67
...shared,
78

89
locales: {
910
root: { label: "English", ...en },
11+
zh: { label: "简体中文", ...zh },
1012
},
1113
};
1214

docs/.vitepress/config/zh.mjs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { defineConfig } from "vitepress";
2+
import pkg from '../../../package.json' with { type: 'json' }
3+
4+
export const zh = defineConfig({
5+
lang: "zh-Hans",
6+
description: "观测你的包裹大小",
7+
8+
themeConfig: {
9+
nav: nav(),
10+
11+
sidebar: {
12+
"/zh/guide/": { base: "/zh/guide/", items: sidebarGuide() },
13+
"/zh/reference/": {
14+
base: "/zh/reference/",
15+
items: sidebarReference(),
16+
},
17+
},
18+
19+
editLink: {
20+
pattern:
21+
"https://github.com/bundlewatch/bundlewatch.io/edit/master/docs/:path",
22+
text: "在GitHub上编辑此页面",
23+
},
24+
25+
outline: {
26+
level: "deep",
27+
},
28+
29+
footer: {
30+
message: "根据 MIT 许可证发布。",
31+
copyright: `版权所有 © 2018-至今 BundleWatch`,
32+
},
33+
},
34+
});
35+
36+
function nav() {
37+
return [
38+
{
39+
text: "指南",
40+
link: "/zh/guide/what-is-it",
41+
activeMatch: "/zh/guide/",
42+
},
43+
{
44+
text: "参考",
45+
link: "/zh/reference/configuration",
46+
activeMatch: "/zh/reference/",
47+
},
48+
{
49+
text: pkg.bundlewatch.version,
50+
items: [
51+
{
52+
text: "Release Notes",
53+
link: "https://github.com/bundlewatch/bundlewatch/releases/tag/v0.4.1",
54+
target: "_blank",
55+
},
56+
{
57+
text: "Contributing",
58+
link: "https://github.com/bundlewatch/bundlewatch/blob/master/CONTRIBUTING.md",
59+
target: "_blank",
60+
},
61+
],
62+
},
63+
];
64+
}
65+
66+
function sidebarGuide() {
67+
return [
68+
{
69+
text: "介绍",
70+
items: [
71+
{ text: "这是什么?", link: "what-is-it" },
72+
{ text: "快速开始", link: "getting-started" },
73+
],
74+
},
75+
{
76+
text: "如何使用",
77+
items: [
78+
{ text: "使用 BundleWatch", link: "using-bundlewatch" },
79+
{ text: "使用配置文件", link: "using-a-config-file" },
80+
{
81+
text: "对比非主分支的构建差异",
82+
link: "diffing-against-branches-other-than-master",
83+
},
84+
{ text: "使用自定义服务器", link: "using-a-custom-server" },
85+
],
86+
},
87+
{
88+
text: "配置、API 和 CLI 参考",
89+
base: "/zh/reference/",
90+
link: "/configuration",
91+
},
92+
];
93+
}
94+
95+
function sidebarReference() {
96+
return [
97+
{
98+
text: "参考",
99+
items: [
100+
{ text: "配置项", link: "configuration" },
101+
{ text: "NodeJS API", link: "nodejs" },
102+
{ text: "CLI 参数", link: "cli" },
103+
],
104+
},
105+
];
106+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: 对比除 Master 以外的分支
3+
description: 如何配置 Bundlewatch 以对比 develop 或 staging 等分支。
4+
---
5+
6+
# 对比除 Master 以外的分支
7+
8+
默认情况下,按照 [使用 Bundlewatch](./using-bundlewatch.md) 指南操作后,Bundlewatch 会将你的 bundle 与 `master` 分支进行对比。
9+
10+
如果你想对比其他分支(例如 `develop`),请设置以下 CI 环境变量:
11+
12+
- `CI_BRANCH_BASE`
13+
14+
如果你使用的是 Travis 或 Drone,这通常会自动设置。
15+
16+
::: info 信息
17+
查看哪些 CI 变量会被自动检测,请参阅 [getCIVars.js 源码](https://github.com/bundlewatch/bundlewatch/blob/master/src/app/config/getCIVars.js)
18+
:::
19+
20+
要对比多个分支(例如 `develop``staging`),请在 `package.json` 的 Bundlewatch 配置中添加 `trackBranches` 选项:
21+
22+
```json
23+
{
24+
"bundlewatch": {
25+
"files": [
26+
{
27+
"path": "myfolder/*.js",
28+
"maxSize": "100kB"
29+
}
30+
],
31+
"ci": {
32+
"trackBranches": ["master", "develop", "staging"]
33+
}
34+
}
35+
}
36+
```
37+
38+
更多配置选项,请参阅 [配置参考](../reference/configuration.md)

docs/zh/guide/getting-started.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: 入门指南
3+
description: 分步指导你在项目中安装和设置 Bundlewatch。
4+
---
5+
6+
# 入门指南
7+
8+
本指南将帮助你在项目中安装并设置 Bundlewatch。
9+
10+
## 安装
11+
12+
你可以使用 npm 或 Yarn 安装 Bundlewatch:
13+
14+
### 使用 npm
15+
16+
```bash
17+
npm install bundlewatch --save-dev
18+
```
19+
20+
### 使用 Yarn
21+
22+
```bash
23+
yarn add bundlewatch --dev
24+
```
25+
26+
现在你已经可以开始使用 BundleWatch 了!:tada:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: 使用配置文件
3+
description: 如何通过配置文件或 package.json 配置 Bundlewatch。
4+
---
5+
6+
# 使用配置文件
7+
8+
[Bundlewatch CLI](../reference/cli.md) 可以从 `.json``.js` 文件或你的 `package.json` 文件中读取配置。
9+
10+
- 若要使用自定义配置文件,请在命令行中指定它:
11+
```bash
12+
bundlewatch --config .bundlewatch.config.js
13+
```
14+
- 如果省略 `--config` 标志,Bundlewatch 会在你的 `package.json` 中查找 `bundlewatch` 键。
15+
16+
`package.json` 配置示例:
17+
18+
```json
19+
{
20+
"name": "my package name",
21+
"version": "0.0.1",
22+
"bundlewatch": {
23+
"files": [
24+
{
25+
"path": "myfolder/*.js",
26+
"maxSize": "100kB"
27+
}
28+
]
29+
}
30+
}
31+
```
32+
33+
你也可以直接将配置传递给 [Node.js API](../reference/nodejs.md)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: 使用自定义服务器
3+
description: 如何运行你自己的 Bundlewatch 服务并将项目配置为使用它。
4+
---
5+
6+
# 在 Bundlewatch 中使用自定义服务器
7+
8+
你可以通过 fork 官方服务仓库来运行你自己的 Bundlewatch 服务实例:
9+
10+
https://github.com/bundlewatch/service
11+
12+
在你喜欢的基础设施上启动你自己的实例。
13+
14+
然后,更新你的 Bundlewatch 配置,使其指向你的自定义服务器:
15+
16+
```js
17+
module.exports = {
18+
files: [...],
19+
bundlewatchServiceHost: 'https://my-bundlewatch-service.example.com',
20+
}
21+
```
22+
23+
更多配置选项,请参阅 [配置参考](../reference/configuration.md)

docs/zh/guide/using-bundlewatch.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: 使用 Bundlewatch
3+
description: 如何运行 Bundlewatch、设置 CI 集成以及查看结果。
4+
---
5+
6+
# 基本用法
7+
8+
在你构建好的资源上运行 Bundlewatch 以检查它们的体积:
9+
10+
```bash
11+
yarn run bundlewatch --max-size 100kb ./webpack-build/*.js
12+
```
13+
14+
示例输出:
15+
16+
```
17+
结果详情见: https://ja2r7.app.goo.gl/aDzEQjBVMXxrCgaa7
18+
19+
PASS ./webpack-build/app.js: 30.71KB < 100KB (gzip)
20+
FAIL ./webpack-build/vendor.js: 198.6KB > 100KB (gzip)
21+
22+
BundleWatch FAIL
23+
```
24+
25+
该命令会在终端中立即给出反馈。要在 GitHub Pull Request 上启用构建状态报告,请按照以下步骤操作。
26+
27+
## 为 GitHub PR 添加构建状态
28+
29+
Bundlewatch 可以直接在你的 GitHub Pull Request 上报告其状态。
30+
31+
<div align="center">
32+
<img alt="build status preview" data-zoomable src="/build-status-preview.png" width="700px">
33+
</div>
34+
35+
## 设置 CI 认证
36+
37+
你需要提供一个 `BUNDLEWATCH_GITHUB_TOKEN`,以便 Bundlewatch 能够更新你的 PR 状态。你可以在以下地址获取你的 token:
38+
39+
https://service.bundlewatch.io/setup-github
40+
41+
在你的 CI 环境中将此 token 设置为环境变量。
42+
43+
## CI 所需环境变量
44+
45+
在 CI 中,Bundlewatch 需要以下环境变量:
46+
47+
- `CI_REPO_OWNER`(例如 github.com/facebook/react 中的 `facebook`
48+
- `CI_REPO_NAME`(例如 github.com/facebook/react 中的 `react`
49+
- `CI_COMMIT_SHA`
50+
- `CI_BRANCH`
51+
52+
::: info
53+
如果你使用的是 Travis、CircleCI、Wrecker 或 Drone,这些变量通常会自动设置。
54+
详情见 [getCIVars.js](https://github.com/bundlewatch/bundlewatch/blob/master/src/app/config/getCIVars.js)
55+
:::
56+
57+
## 查看结果详情
58+
59+
设置完成后,Bundlewatch 会在你的 PR 上发布构建状态。点击 _details_ 链接可以查看结果详情。
60+
61+
<div align="center">
62+
<img alt="build results preview" data-zoomable src="/build-results-preview.png" width="700px">
63+
</div>
64+
65+
---
66+
67+
- [配置 Bundlewatch](./using-a-config-file.md)
68+
- [对比其他分支](./diffing-against-branches-other-than-master.md)
69+
- [配置参考](../reference/configuration.md)

docs/zh/guide/what-is-it.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: 什么是 Bundlewatch?
3+
description: 了解 Bundlewatch 是什么,以及它如何帮助你监控 bundle 体积。
4+
---
5+
6+
# 什么是 Bundlewatch?
7+
8+
Bundlewatch 是一个检查你打包后的浏览器资源体积的工具,帮助你防止文件体积出现意外增长。
9+
10+
## 为什么要使用 Bundlewatch?
11+
12+
Bundlewatch 可以帮助你:
13+
14+
- 检测新的依赖是否导致 bundle 体积膨胀
15+
- 捕捉意外的大型导入
16+
- 确保资源被正确压缩
17+
- 防止 bundle 体积随时间回退变大
18+
19+
::: tip
20+
在构建生产环境资源后,在 CI 流水线中运行 `bundlewatch`。Bundlewatch 会跟踪这些文件,并在它们超过你配置的体积限制时提醒你。
21+
:::
22+
23+
如果某个文件超过了最大体积,Bundlewatch 会在你的 GitHub Pull Request 上更新状态,并且可以阻止未通过检查的合并。
24+
25+
---
26+
27+
更多详情请参阅 [入门指南](./getting-started.md)[配置参考](../reference/configuration.md)

0 commit comments

Comments
 (0)