Skip to content

Commit cf3652e

Browse files
authored
docs: update (#4)
* chore: update deps * chore: update siteTitle, add local search * docs: update
1 parent d24b1f8 commit cf3652e

File tree

12 files changed

+1408
-708
lines changed

12 files changed

+1408
-708
lines changed

.eslintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.vitepress/config.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default defineConfig({
7777
themeConfig: {
7878
// https://vitepress.dev/reference/default-theme-config
7979
logo: '/logo.svg',
80-
siteTitle: 'Vitesse',
80+
siteTitle: 'Vitesse Uni App',
8181
nav: [
8282
{ text: '快速开始', link: '/getting-started/installation', activeMatch: '/getting-started' },
8383
{ text: '指南', link: '/guide/concepts/auto-imports', activeMatch: '/guide' },
@@ -179,5 +179,29 @@ export default defineConfig({
179179
pattern: 'https://github.com/uni-helper/vitesse-uni-app-docs/edit/main/:path',
180180
text: '在 GitHub 上编辑本页',
181181
},
182+
183+
search: {
184+
provider: 'local',
185+
options: {
186+
locales: {
187+
zh: {
188+
translations: {
189+
button: {
190+
buttonText: '搜索文档',
191+
buttonAriaLabel: '搜索文档'
192+
},
193+
modal: {
194+
noResultsText: '无法找到相关结果',
195+
resetButtonTitle: '清除查询条件',
196+
footer: {
197+
selectText: '选择',
198+
navigateText: '切换'
199+
}
200+
}
201+
}
202+
}
203+
}
204+
}
205+
},
182206
},
183207
})

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import antfu from '@antfu/eslint-config'
2+
3+
export default antfu()

getting-started/data-fetching.md

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
# 数据获取
22

3-
你可以使用任何你喜欢的第三方请求库来获取数据。默认情况下,直接使用 `uni.request` 即可
3+
你可以使用你喜欢的第三方请求库来获取数据。一般情况下,直接使用 `uni-app` 内置方法即可
44

5-
## `uni.request`
5+
## `uni-app` 内置方法
66

7-
这是 uni 内置的网络请求方法
7+
`uni-app` 提供了 [uni.request](https://uniapp.dcloud.net.cn/api/request/request.html)[uni.uploadFile](https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile)[uni.downloadFile](https://uniapp.dcloud.net.cn/api/request/network-file.html#downloadfile)[WebSocket](https://uniapp.dcloud.net.cn/api/request/websocket.html) 等支持。一般情况下,你可以直接使用它们
88

9-
```ts
10-
uni.request({
11-
url: 'https://www.example.com/request',
12-
data: {
13-
text: 'uni.request'
14-
},
15-
header: {
16-
'custom-header': 'hello' // 自定义请求头信息
17-
},
18-
success: (res) => {
19-
console.log(res.data)
20-
}
21-
})
22-
```
9+
## axios
2310

11+
如果你更喜欢 [axios](https://github.com/axios/axios) 及其相关生态,你可以使用 [@uni-helper/axios-adapter](https://github.com/uni-helper/axios-adapter)。它是专为 `uni-app` 打造的 `axios` 适配器,支持全平台!
12+
13+
```ts
14+
import axios from 'axios'
15+
import { createUniAppAxiosAdapter } from '@uni-helper/axios-adapter'
2416

25-
::: tip
26-
你可以在[这里](https://uniapp.dcloud.net.cn/api/request/request.html#)阅读文档。
27-
:::
17+
axios.defaults.adapter = createUniAppAxiosAdapter()
18+
const { data, isFinished } = useAxios('/user?ID=12345')
19+
```
2820

29-
## uni-network
21+
## @uni-helper/uni-network
3022

31-
这是一个为 `uni-app` 打造的 [基于 Promise](https://javascript.info/promise-basics) 的 HTTP 客户端,灵感和代码绝大部分源于 `[email protected]`
23+
[@uni-helper/uni-network](https://github.com/uni-helper/uni-network) 是一个为 `uni-app` 打造的基于 `Promise` 的 HTTP 客户端,灵感和代码绝大部分源于 `[email protected]``@uni-helper/uni-network` 在底层做了 `uni-app` 适配,体积更小,TypeScript 类型更贴近 `uni-app`
3224

3325
```ts
34-
import un from '@uni-helper/uni-network'
26+
import { un } from '@uni-helper/uni-network'
3527

3628
try {
3729
const response = await un.get('/user?ID=12345')
@@ -41,23 +33,3 @@ catch (error) {
4133
console.error(error)
4234
}
4335
```
44-
45-
::: tip
46-
你可以在[这里](https://github.com/uni-helper/uni-network)阅读文档。
47-
:::
48-
49-
## axios
50-
51-
如果你更喜欢 axios 或者为了享受其相关生态,你还可以使用由 Uni Helper 团队开发的 [axios-adapter](https://github.com/uni-helper/axios-adapter),它是专为 uni-app 打造的 axios 适配器,支持全平台!
52-
53-
```ts
54-
import axios from 'axios'
55-
import { createUniAppAxiosAdapter } from '@uni-helper/axios-adapter'
56-
57-
axios.defaults.adapter = createUniAppAxiosAdapter()
58-
const { data, isFinished } = useAxios('/user?ID=12345')
59-
```
60-
61-
::: tip
62-
你可以阅读 [axios 的文档](https://axios-http.com/docs/intro)[axios-adapter 的文档](https://github.com/uni-helper/axios-adapter)了解更多信息。
63-
:::

getting-started/deployment.md

Lines changed: 144 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,166 @@ pnpm build:h5
1414

1515
## 小程序
1616

17-
使用下面的命令来打包:
17+
以微信小程序为例,使用下面的命令来打包:
1818

1919
```bash
20-
# 微信小程序
2120
pnpm build:mp-weixin
2221
```
2322

2423
产物位于 `dist/build/mp-weixin`, 使用微信开发者工具上传即可。
2524

2625
::: tip
27-
如若想自动上传到微信小程序,可查看[这里](https://juejin.cn/post/7272316909051346959)
26+
如果想自动上传到微信小程序,可直接使用 [uni-mini-ci](https://www.npmjs.com/package/uni-mini-ci),或参考 [这篇文章](https://juejin.cn/post/7272316909051346959) 自行配置。
2827
:::
2928

30-
::: tip
31-
要发行其他小程序,执行 `pnpm build:mp-<platform>`打包,并使用对应开发者工具上传即可,具体可查看 package.json 的 scripts 部分。
32-
:::
29+
要发行其他小程序,执行 `pnpm build:mp-<platform>`打包,并使用对应开发者工具上传即可,具体可查看 `package.json``scripts` 部分。
3330

34-
## App
31+
## APP
3532

3633
### 离线打包
3734

3835
- [android](https://nativesupport.dcloud.net.cn/AppDocs/usesdk/android.html)
3936
- [ios](https://nativesupport.dcloud.net.cn/AppDocs/usesdk/ios.html)
4037

4138
::: warning
42-
你任然可以使用 HBuilderX 提供的"安心"打包功能,但是由于这种方式强依赖 HBuilderX,故不做推荐
39+
你仍然可以使用 HBuilderX 提供的“安心”打包功能,但是由于这种方式强依赖 HBuilderX,故不做推荐
4340
:::
41+
42+
## 兼容性
43+
44+
默认情况下,你不需要调整兼容性相关的构建配置,这是因为较新的浏览器、手机、小程序运行环境提供了较好的兼容性支持。
45+
46+
但理想很丰满,现实很骨感,总有用户不想换掉自己的旧设备、旧浏览器,而你恰好又需要关怀这些用户。这时候,你就需要调整兼容性相关的构建配置了。
47+
48+
### VueCLI
49+
50+
对于部分正在使用 VueCLI 的历史项目,请参考 [文档](https://cli.vuejs.org/zh/config/#transpiledependencies) 设置 `transpileDependencies`,VueCLI 会自动增加 JavaScript 和 CSS 的支持。
51+
52+
### Vite
53+
54+
Vite 底层使用了 [esbuild](https://esbuild.github.io/),你可以设置 `build.target``build.cssTarget` 来做兼容。
55+
56+
```ts
57+
import { defineConfig } from 'vite'
58+
import uni from '@dcloudio/vite-plugin-uni'
59+
60+
export default defineConfig({
61+
build: {
62+
// esbuild 最低支持 es6
63+
target: 'es6', // JavaScript 语法支持
64+
cssTarget: 'es6' // CSS 语法支持
65+
},
66+
plugins: [uni()]
67+
})
68+
69+
```
70+
71+
但 esbuild 没有覆盖到所有需要兼容的情况。对于 JavaScript,esbuild 没有注入 [Polyfills](https://developer.mozilla.org/en-US/docs/Glossary/Polyfill),这也意味着部分 JavaScript API 不可用。遗憾的是,你无法直接使用 `@vitejs/plugin-legacy``@vitejs/plugin-legacy-swc`,甚至设置 `@dcloudio/vite-plugin-uni` 中的 `viteLegacyOptions`[只会在 H5 中 生效](https://github.com/dcloudio/uni-app/issues/3842),此时只可以使用 `core-js` 来手动注入。
72+
73+
::: code-group
74+
75+
```ts [src/main.ts]
76+
/** #ifdef MP */
77+
// 只有构建小程序时手动注入 Polyfills
78+
// 可以按实际情况调整
79+
import 'core-js/actual/array/at'
80+
// ❌ 不要像下面这样做,会占用大量小程序体积且没有必要
81+
// import 'core-js/actual'
82+
/** #endif */
83+
import { createSSRApp } from 'vue'
84+
import { createPinia } from 'pinia'
85+
import App from './App.vue'
86+
87+
const pinia = createPinia()
88+
89+
export function createApp() {
90+
const app = createSSRApp(App).use(pinia);
91+
return {
92+
app,
93+
}
94+
}
95+
```
96+
97+
```ts [vite.config.ts]
98+
import { defineConfig } from 'vite'
99+
import uni from '@dcloudio/vite-plugin-uni'
100+
import { isH5 } from '@uni-helper/uni-env'
101+
import legacy from 'vite-plugin-legacy'
102+
// 或者使用 vite-plugin-legacy-swc
103+
// import legacy from 'vite-plugin-legacy-swc'
104+
105+
export default defineConfig({
106+
build: {
107+
// 最低支持 es6
108+
target: 'es6', // JavaScript 语法支持
109+
cssTarget: 'es6' // CSS 语法支持
110+
},
111+
plugins: [
112+
uni(),
113+
// 只有构建 H5 时应用插件自动注入 Polyfills
114+
// 可以按实际情况调整
115+
isH5 ? legacy() : null
116+
]
117+
})
118+
119+
```
120+
121+
:::
122+
123+
::: tip
124+
你可以使用 [core-js-compat](https://github.com/zloirock/core-js/blob/master/packages/core-js-compat/README.md) 来确定具体的 Polyfills。
125+
:::
126+
127+
对于 CSS,可以使用 [PostCSS](https://postcss.org/)[postcss-preset-env](https://github.com/csstools/postcss-plugins/tree/main/plugin-packs/postcss-preset-env)
128+
129+
```bash
130+
pnpm install postcss postcss-preset-env -D
131+
```
132+
133+
::: code-group
134+
135+
```ts [postcss.config.ts]
136+
import postcssPresetEnv from 'postcss-preset-env';
137+
138+
const plugins = []
139+
if (process.env.NODE_ENV === 'production') {
140+
plugins.push(
141+
postcssPresetEnv({
142+
// 自定义相应目标
143+
// 微信小程序 2.11.2 开始支持 Vue3,对应 chrome53 和 ios10
144+
browsers: ['chrome>=53', 'ios>=10']
145+
})
146+
)
147+
}
148+
149+
export default {
150+
plugins
151+
}
152+
```
153+
154+
```ts [vite.config.ts]
155+
import { defineConfig } from 'vite'
156+
import uni from '@dcloudio/vite-plugin-uni'
157+
import postcssConfig from './postcss.config'
158+
159+
export default defineConfig({
160+
build: {
161+
cssTarget: 'chrome61'
162+
},
163+
css: {
164+
postcss: postcssConfig
165+
},
166+
plugins: [uni()]
167+
})
168+
169+
```
170+
171+
:::
172+
173+
::: warning
174+
你可以在 [dcloudio/uni-app#3367](https://github.com/dcloudio/uni-app/issues/3367) 了解为什么要在 Vite 配置文件内设置 PostCSS。
175+
:::
176+
177+
### 构建小程序
178+
179+
对于小程序,你可以直接设置小程序最低基础库要求,以排除部分过于老旧的设备。

getting-started/installation.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
### 前置依赖
1515

16-
- **Node.js** - v16.10.0 或者更高
17-
- **文本编辑器** - 推荐使用 VS Code 并使用 Volar 插件
18-
- **终端** - 为了运行 `uni` 命令
16+
- **Node.js** - v18.19.0 或者更高
17+
- **文本编辑器** - 推荐使用 [VS Code](https://code.visualstudio.com/) 并使用 [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) 插件
18+
- **终端** - 为了运行 `uni` 命令,Windows 推荐 Git Bash,Linux 和 macOS 推荐 zsh
1919

2020
::: details 最佳实践
2121

22-
- **Node.js**: 总是使用偶数版本 (例如 18, 20)
23-
- **Volar**: 推荐启用接管模式 (takeover)
22+
- **Node.js**: 总是使用偶数版本 (即 [LTS 版本](https://nodejs.org/en/about/previous-releases),例如 18, 20)
23+
- **Volar**: 推荐启用 [接管模式 takeover mode](https://cn.vuejs.org/guide/typescript/overview#volar-takeover-mode)
24+
2425
:::
2526

2627
打开终端,然后使用以下命令:

getting-started/introduction.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# 介绍
22

3-
vitess-uni-app 是一个开源模板,具有直观且可扩展的方式来使用 `Vue` & `uni-app` 创建类型安全、高性能和生产级的跨端应用。
3+
vitess-uni-app 是一个基于 `Vue` `uni-app` 的开源模板,采用直观且可扩展的方式创建类型安全、高性能和生产级的跨端应用。你可以直接开始编写 `.vue` 文件,而无需从头开始配置
44

5-
你可以直接开始编写 `.vue` 文件,而无需从头开始配置。
6-
7-
vitesse-uni-app 没有绑定编辑器,你可以使用任何方式任何编辑器进行开发。
5+
vitesse-uni-app 灵感源于 [vitesse](https://github.com/antfu/vitesse)
86

97
## 为什么
108

11-
- 不要 HBuilderX
12-
- 拥抱 npm 生态
9+
`uni-app` 背后的公司 DCloudio 选择创建自己的生态,比如 HBuilderX、uni_modules 等。这部分工作对部分开发者来说意义非凡,他们可以轻松上手并享受社区提供的一切资源。
10+
11+
但是,`uni-app` 社区生态远不如 npm 生态繁荣,我们常常需要求助于 npm 生态来实现部分需求,而 `uni-app` 的黑盒性阻碍了这一点。
12+
13+
vitesse-uni-app 充分拥抱开放生态,比如 VS Code 和 npm,希望能带给你更好的体验。
1314

1415
## 主要依赖
1516

0 commit comments

Comments
 (0)