Skip to content

Commit 02ae18e

Browse files
committed
docs(useage): addon auto import docs
1 parent d8742f7 commit 02ae18e

File tree

6 files changed

+231
-10
lines changed

6 files changed

+231
-10
lines changed

packages/hooks/README.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,73 @@ function Index() {
112112
</script>
113113
```
114114

115+
## 🎰 auto-import
116+
117+
We provide the @taro-hooks/plugin-auto-import plugin to help you quickly use the [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import) capability.
118+
119+
```bash
120+
# npm
121+
$ npm i @taro-hooks/plugin-auto-import
122+
# yarn
123+
$ yarn add @taro-hooks/plugin-auto-import
124+
# pnpm
125+
$ pnpm add @taro-hooks/plugin-auto-import
126+
```
127+
128+
```js
129+
// config/index.js
130+
const config = {
131+
// ...
132+
// The main prerequisite is that you have installed the plugin for the corresponding framework.
133+
plugins: [
134+
// If you are using vue3, please install the @taro-hooks/plugin-vue plugin beforehand.
135+
'@taro-hooks/plugin-vue'
136+
// If using React/PReact/Nerv, please pre-install the @taro-hooks/plugin-react plugin.
137+
'@taro-hooks/plugin-react',
138+
// Finally, the auto-import plugin is configured
139+
[
140+
'@taro-hooks/plugin-auto-import',
141+
{
142+
// your options, see configuration: https://github.com/antfu/unplugin-auto-import#configuration
143+
}
144+
]
145+
],
146+
// ...
147+
};
148+
```
149+
150+
- React/PReact/Nerv
151+
152+
```jsx
153+
function Index() {
154+
const env = useEnv();
155+
156+
return <View>current env: {env}</View>;
157+
}
158+
```
159+
160+
- Vue3
161+
162+
```html
163+
<template>
164+
<view>current env: {{env}}</view>
165+
</template>
166+
167+
<script setup lang="ts">
168+
const env = useEnv();
169+
</script>
170+
```
171+
115172
## 📦 Packages
116173

117-
| packages | downloads | version | license |
118-
| :------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: |
119-
| ![taro-hooks](https://img.shields.io/badge/taro--hooks-pkg-blueviolet?) | ![taro-hooks](https://img.shields.io/npm/dm/taro-hooks.svg) | ![taro-hooks](https://img.shields.io/npm/v/taro-hooks?) | ![taro-hooks](https://img.shields.io/npm/l/taro-hooks?) |
120-
| ![@taro-hooks/ahooks](https://img.shields.io/badge/%40taro--hooks%2Fahooks-pkg-blueviolet?) | ![@taro-hooks/ahooks](https://img.shields.io/npm/dm/@taro-hooks/ahooks.svg) | ![@taro-hooks/ahooks](https://img.shields.io/npm/v/@taro-hooks/ahooks?) | ![@taro-hooks/ahooks](https://img.shields.io/npm/l/@taro-hooks/ahooks?) |
121-
| ![@taro-hooks/plugin-vue](https://img.shields.io/badge/%40taro--hooks%2Fplugin--vue-pkg-blueviolet?) | ![@taro-hooks/plugin-vue](https://img.shields.io/npm/dm/@taro-hooks/plugin-vue.svg) | ![@taro-hooks/plugin-vue](https://img.shields.io/npm/v/@taro-hooks/plugin-vue?) | ![@taro-hooks/plugin-vue](https://img.shields.io/npm/l/@taro-hooks/plugin-vue?) |
122-
| ![@taro-hooks/plugin-react](https://img.shields.io/badge/%40taro--hooks%2Fplugin--react-pkg-blueviolet?) | ![@taro-hooks/plugin-react](https://img.shields.io/npm/dm/@taro-hooks/plugin-react.svg) | ![@taro-hooks/plugin-react](https://img.shields.io/npm/v/@taro-hooks/plugin-react?) | ![@taro-hooks/plugin-react](https://img.shields.io/npm/l/@taro-hooks/plugin-react?) |
123-
| ![@taro-hooks/use-request](https://img.shields.io/badge/%40taro--hooks%2Fuse--request-pkg-blueviolet?) | ![@taro-hooks/use-request](https://img.shields.io/npm/dm/@taro-hooks/use-request.svg) | ![@taro-hooks/use-request](https://img.shields.io/npm/v/@taro-hooks/use-request?) | ![@taro-hooks/use-request](https://img.shields.io/npm/l/@taro-hooks/use-request?) |
174+
| packages | downloads | version | license |
175+
| :-----------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: |
176+
| ![taro-hooks](https://img.shields.io/badge/taro--hooks-pkg-blueviolet?) | ![taro-hooks](https://img.shields.io/npm/dm/taro-hooks.svg) | ![taro-hooks](https://img.shields.io/npm/v/taro-hooks?) | ![taro-hooks](https://img.shields.io/npm/l/taro-hooks?) |
177+
| ![@taro-hooks/ahooks](https://img.shields.io/badge/%40taro--hooks%2Fahooks-pkg-blueviolet?) | ![@taro-hooks/ahooks](https://img.shields.io/npm/dm/@taro-hooks/ahooks.svg) | ![@taro-hooks/ahooks](https://img.shields.io/npm/v/@taro-hooks/ahooks?) | ![@taro-hooks/ahooks](https://img.shields.io/npm/l/@taro-hooks/ahooks?) |
178+
| ![@taro-hooks/plugin-vue](https://img.shields.io/badge/%40taro--hooks%2Fplugin--vue-pkg-blueviolet?) | ![@taro-hooks/plugin-vue](https://img.shields.io/npm/dm/@taro-hooks/plugin-vue.svg) | ![@taro-hooks/plugin-vue](https://img.shields.io/npm/v/@taro-hooks/plugin-vue?) | ![@taro-hooks/plugin-vue](https://img.shields.io/npm/l/@taro-hooks/plugin-vue?) |
179+
| ![@taro-hooks/plugin-react](https://img.shields.io/badge/%40taro--hooks%2Fplugin--react-pkg-blueviolet?) | ![@taro-hooks/plugin-react](https://img.shields.io/npm/dm/@taro-hooks/plugin-react.svg) | ![@taro-hooks/plugin-react](https://img.shields.io/npm/v/@taro-hooks/plugin-react?) | ![@taro-hooks/plugin-react](https://img.shields.io/npm/l/@taro-hooks/plugin-react?) |
180+
| ![@taro-hooks/use-request](https://img.shields.io/badge/%40taro--hooks%2Fuse--request-pkg-blueviolet?) | ![@taro-hooks/use-request](https://img.shields.io/npm/dm/@taro-hooks/use-request.svg) | ![@taro-hooks/use-request](https://img.shields.io/npm/v/@taro-hooks/use-request?) | ![@taro-hooks/use-request](https://img.shields.io/npm/l/@taro-hooks/use-request?) |
181+
| ![@taro-hooks/plugin-auto-import](https://img.shields.io/badge/%40taro--hooks%2Fplugin-auto-import-pkg-blueviolet?) | ![@taro-hooks/plugin-auto-import](https://img.shields.io/npm/dm/@taro-hooks/plugin-auto-import.svg) | ![@taro-hooks/plugin-auto-import](https://img.shields.io/npm/v/@taro-hooks/plugin-auto-import?) | ![@taro-hooks/plugin-auto-import](https://img.shields.io/npm/l/@taro-hooks/plugin-auto-import?) |
124182

125183
## 🗨️ Communication
126184

website/docs/intro.mdx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@ sidebar_position: 1
2626

2727
### 框架支持
2828

29-
**taro-hooks** 中可以使用 **React/Vue** 开发体验, 具体请参考:
29+
**taro-hooks** 中可以使用 **React/PReact/Nerv/Vue** 开发体验, 具体请参考:
3030

31-
- [基础教程 ———— React](/docs/quick/react-useage)
31+
- [基础教程 ———— React/PReact/Nerv](/docs/quick/react-useage)
3232
- [基础教程 ———— Vue](/docs/quick/vue-useage)
3333

3434
import Tabs from '@theme/Tabs';
3535
import TabItem from '@theme/TabItem';
3636

3737
<Tabs defaultValue="React" groupId="codeDisplayGroup">
38-
<TabItem value="React" label="React">
38+
<TabItem value="React" label="React/PReact/Nerv">
3939

4040
```bash
41+
# npm
4142
$ npm i @taro-hooks/plugin-react
43+
# yarn
44+
$ yarn add @taro-hooks/plugin-react
45+
# pnpm
46+
$ pnpm add @taro-hooks/plugin-react
4247
```
4348
```js {3} title="project/config/index.js"
4449
const config = {
@@ -66,7 +71,12 @@ export default () => {
6671
<TabItem value="Vue" label="Vue">
6772

6873
```bash
74+
# npm
6975
$ npm i @taro-hooks/plugin-vue
76+
# yarn
77+
$ yarn add @taro-hooks/plugin-vue
78+
# pnpm
79+
$ pnpm add @taro-hooks/plugin-vue
7080
```
7181
```js {3} title="project/config/index.js"
7282
const config = {

website/docs/quick/auto-import.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: AutoImport 教程
3+
sidebar_position: 4
4+
---
5+
6+
## 概述
7+
8+
**@taro-hooks/plugin-auto-import** 是内置了 **taro-hooks preset****unplugin-auto-import****taro** 插件. 帮助大家无需再每个页面引入 **taro-hooks** 而 快捷使用我们提供的 **hooks**
9+
10+
## 配置
11+
12+
### 安装 **taro-hooks**
13+
14+
```bash
15+
# npm
16+
$ npm i taro-hooks
17+
# yarn
18+
$ yarn add taro-hooks
19+
# pnpm
20+
$ pnpm add taro-hooks
21+
```
22+
23+
### 安装插件
24+
25+
首先需要下载 **@taro-hooks/plugin-auto-import** 插件
26+
27+
```bash
28+
# npm
29+
$ npm i @taro-hooks/plugin-auto-import
30+
# yarn
31+
$ yarn add @taro-hooks/plugin-auto-import
32+
# pnpm
33+
$ pnpm add @taro-hooks/plugin-auto-import
34+
```
35+
36+
### 项目配置
37+
38+
```js title="config/index.js"
39+
const config = {
40+
// ...
41+
// 主要前提是您已经安装了对应框架的插件
42+
plugins: [
43+
// 若使用 vue3, 请预先安装 @taro-hooks/plugin-vue 插件
44+
'@taro-hooks/plugin-vue'
45+
// 若使用 React/PReact/Nerv, 请预先安装 @taro-hooks/plugin-react 插件
46+
'@taro-hooks/plugin-react',
47+
// 最后配置 auto-import 插件 (此为直接使用不需要客制化的情况)
48+
'@taro-hooks/plugin-auto-import'
49+
],
50+
// ...
51+
};
52+
```
53+
54+
若您需要渗透配置至 [**unplugin-auto-import**](https://github.com/antfu/unplugin-auto-import) 中. 可直接在第二个参数中传递需要渗透的 [**Options**](https://github.com/antfu/unplugin-auto-import#configuration)
55+
56+
```js title="config/index.js"
57+
const config = {
58+
// ...
59+
// 主要前提是您已经安装了对应框架的插件
60+
plugins: [
61+
// 若使用 vue3, 请预先安装 @taro-hooks/plugin-vue 插件
62+
'@taro-hooks/plugin-vue'
63+
// 若使用 React/PReact/Nerv, 请预先安装 @taro-hooks/plugin-react 插件
64+
'@taro-hooks/plugin-react',
65+
// 最后配置 auto-import 插件
66+
[
67+
'@taro-hooks/plugin-auto-import',
68+
{
69+
// your options
70+
}
71+
]
72+
],
73+
// ...
74+
};
75+
```
76+
77+
## 使用
78+
79+
我们在插件中已经配置好了 **taro-hooks** 相关的 **importMap**. 故您现在无需引用即可在项目中使用
80+
81+
### React/PReact/Nerv
82+
83+
```jsx
84+
function Index() {
85+
const env = useEnv();
86+
87+
return <View>current env: {env}</View>;
88+
}
89+
```
90+
91+
### Vue3
92+
93+
```html
94+
<template>
95+
<view>current env: {{env}}</view>
96+
</template>
97+
98+
<script setup lang="ts">
99+
const env = useEnv();
100+
</script>
101+
```
102+
103+
## 原理
104+
105+
插件依赖了 **taro-hooks** 包中产出的 **metadata.json** 元数据文件. 若您需要高度自定义. 可使用该文件完成自定义的 **ImportMap**.
106+
107+
详细代码见: [**plugin-auto-import**](https://github.com/innocces/taro-hooks/blob/next/packages/plugin-auto-import/src/index.ts#L23)

website/docs/quick/react-useage.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@ sidebar_position: 2
99

1010
## 配置
1111

12+
### 安装 **taro-hooks**
13+
14+
```bash
15+
# npm
16+
$ npm i taro-hooks
17+
# yarn
18+
$ yarn add taro-hooks
19+
# pnpm
20+
$ pnpm add taro-hooks
21+
```
22+
1223
### 安装插件
1324

1425
首先需要下载 **@taro-hooks/plugin-react** 插件
1526

1627
```bash
28+
# npm
1729
$ npm i @taro-hooks/plugin-react
30+
# yarn
31+
$ yarn add @taro-hooks/plugin-react
32+
# pnpm
33+
$ pnpm add @taro-hooks/plugin-react
1834
```
1935

2036
### 项目配置
@@ -27,6 +43,8 @@ const config = {
2743
};
2844
```
2945

46+
> 我们也配套提供了适配 `unplugin-auto-import` 的插件 [`@taro-hooks/plugin-auto-import`](/docs/quick/auto-import)
47+
3048
> 注意: 插件内部会检测当前项目的框架和依赖状态, 若您的项目不是 **React** 的项目, 那么很可能无法正常启动.
3149
3250
## **Hooks**

website/docs/quick/vue-useage.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,39 @@ import UseTaroContext from '@vue-demo/useContext/index.vue'
2323

2424
## 配置
2525

26+
### 安装 **taro-hooks**
27+
28+
```bash
29+
# npm
30+
$ npm i taro-hooks
31+
# yarn
32+
$ yarn add taro-hooks
33+
# pnpm
34+
$ pnpm add taro-hooks
35+
```
36+
2637
### 安装插件
2738

2839
首先需要下载 **@taro-hooks/plugin-vue** 插件
2940

3041
```bash
42+
# npm
3143
$ npm i @taro-hooks/plugin-vue
44+
# yarn
45+
$ yarn add @taro-hooks/plugin-vue
46+
# pnpm
47+
$ pnpm add @taro-hooks/plugin-vue
3248
```
3349

3450
> 建议您同时下载 **@taro-hooks/shared** 插件用于转换一些等同状态的 **state**
3551
3652
```bash
53+
# npm
3754
$ npm i @taro-hooks/shared
55+
# yarn
56+
$ yarn add @taro-hooks/shared
57+
# pnpm
58+
$ pnpm add @taro-hooks/shared
3859
```
3960

4061
### 项目配置
@@ -47,6 +68,8 @@ const config = {
4768
};
4869
```
4970

71+
> 我们也配套提供了适配 `unplugin-auto-import` 的插件 [`@taro-hooks/plugin-auto-import`](/docs/quick/auto-import)
72+
5073
> 注意: 插件内部会检测当前项目的框架和依赖状态, 若您的项目不是 **Vue3** 的项目, 那么很可能无法正常启动.
5174
5275
## **Hooks**

website/docusaurus.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ const config = {
264264
label: 'Discord',
265265
href: 'https://discord.gg/XrrbdDCpKg',
266266
},
267+
{
268+
label: 'Tg',
269+
href: 'https://t.me/+liVrD6TyPV1lZmJl',
270+
},
267271
{
268272
label: '使用案例',
269273
href: 'https://github.com/taro-hooks/user-cases',
@@ -307,6 +311,7 @@ const config = {
307311
label: 'buy me coffee',
308312
href: 'https://www.buymeacoffee.com/innocces?ref=widget-1376490',
309313
},
314+
{ label: 'afdian', href: 'https://afdian.net/a/innocces' }
310315
],
311316
},
312317
],

0 commit comments

Comments
 (0)