Skip to content

Commit 3374f7c

Browse files
committed
chore: add use with taroify
1 parent 0fb9148 commit 3374f7c

File tree

5 files changed

+90
-13
lines changed

5 files changed

+90
-13
lines changed

website/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ docusaurus + tailwindcss
44

55
## 启动项目
66

7-
```cmd
7+
```bash
88
# 安装依赖
99
pnpm install
1010

@@ -16,7 +16,7 @@ pnpm dev
1616

1717
Module not found: Error: Can't resolve '@weapp-tailwindcss/merge' in '/Users/zzy/Projects/weapp-tailwindcss/website/src/theme/ReactLiveScope'
1818

19-
```cmd
19+
```bash
2020
# 本地编译,cd 到根目录下
2121

2222
pnpm build
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# 和 Taroify 一起使用
2+
3+
`taro` 使用 [Taroify](https://taroify.github.io/taroify.com/) 的共同注意点:
4+
5+
由于 [Taroify](https://taroify.github.io/taroify.com/) 引入后,会导致 `tailwindcss` 的样式被覆盖,[Taroify](https://taroify.github.io/taroify.com/) 样式的优先级会高于 `tailwindcss`
6+
7+
## 解决方案
8+
9+
### 修改Taroify引入方式
10+
11+
按照[Taroify](https://taroify.github.io/taroify.com/) 修改引入方式,将 `taroify` 引入方式改成按需引入
12+
13+
```bash
14+
# 安装插件
15+
yarn add babel-plugin-import
16+
```
17+
18+
修改Babel配置文件,修改组件和图标样式的引入方式为手动引入
19+
20+
```js
21+
// babel.config.js
22+
module.exports = {
23+
plugins: [
24+
[
25+
'import',
26+
{
27+
libraryName: '@taroify/core',
28+
libraryDirectory: '',
29+
// 这修改为false
30+
style: false,
31+
// style: false,
32+
},
33+
'@taroify/core',
34+
],
35+
[
36+
'import',
37+
{
38+
libraryName: '@taroify/icons',
39+
libraryDirectory: '',
40+
camel2DashComponentName: false,
41+
// 这里修改为false
42+
style: false,
43+
// style: () => "@taroify/icons/style",
44+
customName: name => name === 'Icon' ? '@taroify/icons/van/VanIcon' : `@taroify/icons/${name}`,
45+
},
46+
'@taroify/icons',
47+
],
48+
],
49+
}
50+
```
51+
52+
### 修改引入样式顺序
53+
54+
修改根目录下的样式引入顺序,优先引入[Taroify](https://taroify.github.io/taroify.com/) 的样式,再引入Tailwindcss的样式
55+
56+
```tsc
57+
// src/app.tsx
58+
59+
import Taro from '@tarojs/taro'
60+
61+
import '@taroify/icons/index.scss'
62+
import '@taroify/core/index.scss'
63+
import './app.scss'
64+
65+
...
66+
67+
```
68+
69+
```scss
70+
// src/app.scss
71+
72+
@use 'tailwindcss/base';
73+
@use 'tailwindcss/components';
74+
@use 'tailwindcss/utilities';
75+
```
76+
77+
## 参见
78+
79+
- [Taroify 官方文档](https://taroify.github.io/taroify.com/)

website/docs/quick-start/install.mdx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,11 @@ module.exports = {
9797
// @tailwind base;
9898
// @tailwind components;
9999
// @tailwind utilities;
100-
```
101-
102-
#### Taro 4.x
103-
104-
环境:Taro 4.x、Sass 1.23+
105100

106-
Taro 4.x 默认使用 `scss` 语法,因此 `app.scss` 文件如下:
107-
108-
```scss title="app.scss"
109-
@use 'tailwindcss/base' as *;
110-
@use 'tailwindcss/components' as *;
111-
@use 'tailwindcss/utilities' as *;
101+
// sass 版本1.25+
102+
// @use 'tailwindcss/base';
103+
// @use 'tailwindcss/components';
104+
// @use 'tailwindcss/utilities';
112105
```
113106

114107
然后在 `app.ts` 里引入这个样式文件即可。

website/routes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"/docs/issues/taro-terser",
5151
"/docs/issues/toast-svg-bug",
5252
"/docs/issues/use-with-nutui",
53+
"/docs/issues/use-with-taroify",
5354
"/docs/issues/use-with-wot-design-uni",
5455
"/docs/issues/v1",
5556
"/docs/mangle",

website/sidebars.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ const issuesSidebar: SidebarConfig = [
238238
type: 'doc',
239239
id: 'issues/use-with-nutui',
240240
},
241+
{
242+
type: 'doc',
243+
id: 'issues/use-with-taroify',
244+
},
241245
{
242246
type: 'doc',
243247
id: 'issues/externalClasses',

0 commit comments

Comments
 (0)