Skip to content

Commit 7e1cb77

Browse files
committed
docs(skill): 优化 weapp-tailwindcss 技能流程并同步文档
1 parent 2a09c1b commit 7e1cb77

7 files changed

Lines changed: 407 additions & 45 deletions

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,24 @@ npx skills add sonofmagic/skills --skill weapp-tailwindcss
8484
- 输出可复制的安装命令、配置文件与验证步骤
8585
- 处理 `rpx` 任意值、`JS` 字符串 class 不生效等常见问题
8686

87-
详细使用说明见 AI 学习中心:
87+
Skill 的执行流程(简版):
88+
89+
1. 先分流任务类型:新接入、迁移、排障、写法规范
90+
2. 先补齐最小上下文:框架、构建器、目标端、Tailwind 版本、是否 `pnpm@10+`
91+
3. 再给出可落地方案,并强制包含回滚路径
92+
93+
Skill 输出默认包含:
94+
95+
- 结论(框架 + Tailwind 版本 + 目标端)
96+
- 修改文件清单
97+
- 可复制配置与命令(默认 `pnpm`
98+
- 验证步骤与预期结果
99+
- 回滚方案
100+
101+
推荐同时阅读:
88102

89103
- [Skill(技能系统)](https://tw.icebreaker.top/docs/ai/basics/skill)
104+
- [Tailwind 写法最佳实践(Skill 引用)](./skills/weapp-tailwindcss/references/tailwind-writing-best-practices.md)
90105

91106
## [安装与使用方式](https://tw.icebreaker.top/docs/quick-start/install)
92107

README_en.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [Features](#features)
2828
- [Plugin Introduction](#plugin-introduction)
2929
- [Requirements](#requirements)
30+
- [AI Skill (For Users)](#ai-skill-for-users)
3031
- [Installation and usage](#installation-and-usage)
3132
- [Migrating from v1 to v2](#migrating-from-v1-to-v2)
3233
- [Configuration reference](#configuration-reference)
@@ -79,6 +80,31 @@ Currently, these plugins support the latest version of the `tailwindcss v3.x.x`
7980

8081
- Node.js `^20.19.0` or `>=22.12.0` (LTS recommended)
8182

83+
## AI Skill (For Users)
84+
85+
If you want AI to integrate `weapp-tailwindcss` in your business project with stable best practices, install the official Skill first:
86+
87+
```bash
88+
npx skills add sonofmagic/skills --skill weapp-tailwindcss
89+
```
90+
91+
After installation, AI can help you with:
92+
93+
- Fast setup for `uni-app` / `taro` / `uni-app x`
94+
- Copy-paste ready commands and config snippets
95+
- Troubleshooting for `rpx` ambiguities, JS string class issues, and `space-y/space-x` behavior
96+
97+
The Skill workflow (short version):
98+
99+
1. Route the request type first: setup, migration, troubleshooting, or coding-style guidance
100+
2. Collect minimum context: framework, bundler, targets, Tailwind version, and whether you use `pnpm@10+`
101+
3. Return an actionable plan with validation steps and rollback guidance
102+
103+
Read more:
104+
105+
- [Skill System](https://tw.icebreaker.top/docs/ai/basics/skill)
106+
- [Tailwind Writing Best Practices (Skill Reference)](./skills/weapp-tailwindcss/references/tailwind-writing-best-practices.md)
107+
82108
## [Installation and usage](https://tw.icebreaker.top/docs/quick-start/install)
83109

84110
## [Migrating from v1 to v2](https://tw.icebreaker.top/docs/migrations/v1)

skills/weapp-tailwindcss/SKILL.md

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
22
name: weapp-tailwindcss
3-
description: 帮助用户在 uni-app、taro、原生小程序与 uni-app x 项目中集成 weapp-tailwindcss,并输出 Tailwind CSS 写法最佳实践(动态类、任意值、rpx、merge、content/@source)与排障步骤
3+
description: 帮助用户在 uni-app、taro、uni-app x 与原生小程序项目中接入和排障 weapp-tailwindcss。Use when 用户提到 weapp-tailwindcss、小程序 Tailwind 不生效、rpx 任意值、JS 字符串 class、space-y/space-x、weapp-tw patch、content/@source、twMerge/cva/tv
44
---
55

66
# weapp-tailwindcss Skill
77

88
用于业务项目接入 `weapp-tailwindcss`,并让 AI 稳定完成“小程序 + 多端”配置、排障与 Tailwind 写法规范落地。
99

10+
> 本 Skill 服务“项目使用者”场景,不是仓库内部二次开发指南。
11+
1012
## 适用任务
1113

1214
- 新项目快速启用 `tailwindcss + weapp-tailwindcss`
@@ -15,68 +17,82 @@ description: 帮助用户在 uni-app、taro、原生小程序与 uni-app x 项
1517
- 样式不生效、`rpx` 任意值异常、`JS` 字符串 class 未转译等问题排查
1618
- 需要“Tailwind class 应该怎么写”的团队规范与代码评审清单
1719

18-
## 先收集信息
20+
## 任务分流
21+
22+
先判断用户当前任务类型,再进入对应流程:
23+
24+
- 集成新项目
25+
- 迁移存量项目
26+
- 排查已有问题
27+
- 沉淀 Tailwind 写法规范
1928

20-
缺少关键信息时,先补齐:
29+
## 信息收集最小集
30+
31+
缺少关键信息时,先补齐后再输出方案:
2132

2233
- 当前框架:`uni-app` / `taro` / `uni-app x` / 原生小程序 / 其他
23-
- 构建工具:`vite` / `webpack5` / `webpack4`
34+
- 构建工具:`vite` / `webpack5` / `webpack4` / 其他
2435
- 目标端:仅小程序,还是小程序 + `H5` / `App`
25-
- `tailwindcss` 主版本(v3 / v4)与包管理器(尤其是否为 `pnpm@10+`
26-
- 当前诉求是“集成配置”、“问题排查”还是“写法规范沉淀”
36+
- `tailwindcss` 主版本(v3 / v4)与包管理器(重点确认是否 `pnpm@10+`
37+
- 运行环境:`node` 版本(建议 `^20.19.0 || >=22.12.0`
38+
- 当前诉求是“集成配置 / 问题排查 / 写法规范沉淀”中的哪一类
2739

2840
## 执行流程
2941

30-
1. 先确定 Tailwind 主版本与扫描方式
42+
### 1) 基线配置(所有任务通用)
3143

32-
- `tailwindcss@3`:使用 `tailwind.config.js``content`
33-
- `tailwindcss@4`:使用入口 CSS 的 `@source`
34-
- 确保扫描范围覆盖真实模板与脚本文件,且排除 `dist` / `unpackage` / `node_modules`
44+
- 先判断 Tailwind 主版本与扫描方式:
45+
- `tailwindcss@3``tailwind.config.js -> content`
46+
- `tailwindcss@4` 用入口 CSS 的 `@source`
47+
- 扫描范围必须覆盖真实模板与脚本文件,并排除 `dist` / `unpackage` / `node_modules`
48+
- 明确 `postinstall` 需要有 `weapp-tw patch`
49+
- 若是 `pnpm@10+`,提醒执行 `pnpm approve-builds weapp-tailwindcss`
50+
- 如怀疑补丁缓存或目标记录异常,可使用 `weapp-tw patch --clear-cache`
3551

36-
2. 安装并激活 `weapp-tailwindcss`
52+
### 2) 按任务类型执行
3753

38-
- 安装 `weapp-tailwindcss`
39-
- `package.json` 添加 `postinstall: "weapp-tw patch"`
40-
- 若使用 `pnpm@10+`,提醒执行 `pnpm approve-builds weapp-tailwindcss`
41-
- 补丁失效时可引导执行 `npx weapp-tw patch --clear-cache`
54+
- 集成/迁移任务:
55+
- 优先读取 [references/integration-playbook.md](references/integration-playbook.md)
56+
- 按框架给出“可复制最小配置”,不要只给概念
57+
- 多端场景下,明确 `disabled` 条件,避免把小程序插件能力无条件作用到纯 `H5`
4258

43-
3. 按框架注册插件并给出最小配置
59+
- 排障任务:
60+
- 优先读取 [references/troubleshooting-playbook.md](references/troubleshooting-playbook.md)
61+
- 先按“症状 -> 最短排查路径”输出步骤,再给修复示例
62+
- 明确每一步“期望现象/验证点”,避免模糊建议
4463

45-
- `uni-app cli vue3 vite`:使用 `weapp-tailwindcss/vite`,并在 `vite.config` 内联注册 `postcss`
46-
- `uni-app cli vue2 webpack`:使用 `weapp-tailwindcss/webpack`(或历史项目按版本选 `webpack4`
47-
- `taro webpack5`:在 `webpackChain` 注册 `UnifiedWebpackPluginV5`
48-
- `taro vite`:用 `weapp-tailwindcss/vite` + 内联 `postcss`,并处理 css 变量注入
49-
- `uni-app x`:使用 `vite` + `weapp-tailwindcss/vite`,按官方专题配置
50-
- 原生小程序:优先引导到官方模板(`gulp` / `webpack`
64+
- 写法规范任务:
65+
- 读取 [references/tailwind-writing-best-practices.md](references/tailwind-writing-best-practices.md)
66+
- 按“推荐写法 / 反例 / 评审清单”输出
67+
- 需要运行时拼类时,优先 `@weapp-tailwindcss/merge` / `cva` / `variants`
68+
- 涉及封装重命名时,提醒 `ignoreCallExpressionIdentifiers`
5169

52-
4. 根据任务类型补充专项指导
70+
### 3) 回归验证(所有任务都要给)
5371

54-
- 如果用户要“写法最佳实践”,读取 [references/tailwind-writing-best-practices.md](references/tailwind-writing-best-practices.md) 并按其中模板输出
55-
- 如果用户要“运行时拼类”,优先推荐 `@weapp-tailwindcss/merge` / `cva` / `variants` 组合
56-
- 如果用户反馈“压缩后失效”,提醒保留关键函数名,或补充 `ignoreCallExpressionIdentifiers`
72+
- 先跑开发态,再跑目标端构建
73+
- 至少验证 3 类样式:基础工具类、任意值(含 `rpx`)、变体/伪类
74+
-`JS/TS` 中 class 不生效,优先检查 `content/@source` 是否覆盖该文件与扩展名
75+
-`space-y-*` / `space-x-*` 不生效,固定优先级:
76+
- 先改结构(子节点落到 `view/text` 或外层补 `view`
77+
- 再评估 `virtualHost`
78+
- 最后才扩展 `cssChildCombinatorReplaceValue`(保持最小标签集合)
5779

58-
5. 验证与回归
80+
## 输出格式要求
5981

60-
- 先跑开发态编译,再跑目标端构建
61-
- 至少验证 3 类样式:基础工具类、任意值(含 `rpx`)、变体/伪类
62-
-`JS/TS` 内 class 不生效,优先检查 `content/@source` 是否覆盖该文件与扩展名
63-
-`space-y-*` / `space-x-*` 不生效,按固定优先级排查:
64-
1. 先改结构(子节点改为 `view/text` 或外层包裹 `view`
65-
2. 再评估 `virtualHost`
66-
3. 最后才扩展 `cssChildCombinatorReplaceValue`
82+
最终输出必须包含:
6783

68-
## 输出要求
84+
1. 结论(适用框架、Tailwind 版本、目标端)
85+
2. 修改文件清单(按文件逐条列出)
86+
3. 可直接复制的配置片段
87+
4. 安装/运行命令(默认 `pnpm`
88+
5. 验证步骤与预期结果
89+
6. 回滚方案(至少一条)
6990

70-
输出结果需包含
91+
若用户要求“规范沉淀”,额外补充
7192

72-
1. 修改文件清单
73-
2. 可直接复制的配置片段
74-
3. 安装/运行命令
75-
4. 验证步骤与预期结果
76-
5. 若用户要求规范沉淀,额外给出:
77-
- 推荐写法(Do)
78-
- 禁止写法(Don't)
79-
- 最小回归检查清单(Code Review Checklist)
93+
- 推荐写法(Do)
94+
- 禁止写法(Don't)
95+
- 最小回归检查清单(Code Review Checklist)
8096

8197
## 关键约束
8298

@@ -89,10 +105,17 @@ description: 帮助用户在 uni-app、taro、原生小程序与 uni-app x 项
89105
- 需要原样透传第三方类名时,优先使用 `weappTwIgnore`
90106
-`space-y-*` / `space-x-*`,默认按 `view + view`(含 `text`)处理,不要假设会自动覆盖全部标签
91107
- `space-y-*` / `space-x-*` 的标签扩展应最小化,只加入业务确实需要的标签,避免选择器污染
108+
- 不要提供与仓库原则冲突的建议:`JS` 转译基于 `classNameSet` 精确命中,禁止启发式兜底转译
92109
- 对版本不确定时,优先给出与官方文档一致的最小可用方案,再做增量优化
93110

94111
## 引用资料
95112

113+
- [references/integration-playbook.md](references/integration-playbook.md)
114+
- 在“新接入/迁移”类问题中优先读取
115+
- 直接复用其中的最小配置骨架与验证清单
116+
- [references/troubleshooting-playbook.md](references/troubleshooting-playbook.md)
117+
- 在“样式不生效/行为异常”类问题中优先读取
118+
- 按症状路径输出排查步骤,不跳步
96119
- [references/tailwind-writing-best-practices.md](references/tailwind-writing-best-practices.md)
97120
- 在用户要求“Tailwind 写法建议、团队规范、代码评审清单、动态类治理”时读取
98121
- 按“决策顺序 + 示例 + 反例 + 验证步骤”输出,不只给概念
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# weapp-tailwindcss 集成清单(最小可用)
2+
3+
本文件用于“新项目接入”与“老项目迁移”场景,目标是快速给出可复制、可验证的最小方案。
4+
5+
## 1. 通用前置检查
6+
7+
1. Node 版本建议 `^20.19.0 || >=22.12.0`
8+
2. 包管理器默认 `pnpm`
9+
3. 明确 Tailwind 主版本:`v3``v4`
10+
4. 明确目标端:仅小程序 or 小程序 + `H5/App`
11+
12+
## 2. 安装与补丁
13+
14+
```bash
15+
pnpm add -D tailwindcss weapp-tailwindcss postcss autoprefixer
16+
```
17+
18+
`package.json` 保持:
19+
20+
```json
21+
{
22+
"scripts": {
23+
"postinstall": "weapp-tw patch"
24+
}
25+
}
26+
```
27+
28+
`pnpm@10+` 额外执行:
29+
30+
```bash
31+
pnpm approve-builds weapp-tailwindcss
32+
```
33+
34+
怀疑缓存或 patch 目标记录异常时:
35+
36+
```bash
37+
npx weapp-tw patch --clear-cache
38+
```
39+
40+
## 3. Tailwind 扫描配置基线
41+
42+
### Tailwind v3(`content`
43+
44+
```js
45+
/** @type {import('tailwindcss').Config} */
46+
module.exports = {
47+
content: ['./src/**/*.{wxml,html,js,ts,jsx,tsx,vue}'],
48+
}
49+
```
50+
51+
### Tailwind v4(`@source`
52+
53+
```css
54+
@import 'tailwindcss';
55+
@source "../src/**/*.{vue,wxml,js,ts,jsx,tsx}";
56+
@source not "../dist/**";
57+
@source not "../unpackage/**";
58+
```
59+
60+
## 4. 框架最小接入骨架
61+
62+
### uni-app cli vue3 vite
63+
64+
```ts
65+
import uni from '@dcloudio/vite-plugin-uni'
66+
import autoprefixer from 'autoprefixer'
67+
import tailwindcss from 'tailwindcss'
68+
import { defineConfig } from 'vite'
69+
import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'
70+
71+
export default defineConfig({
72+
plugins: [uni(), uvtw()],
73+
css: {
74+
postcss: {
75+
plugins: [tailwindcss(), autoprefixer()],
76+
},
77+
},
78+
})
79+
```
80+
81+
### taro webpack5
82+
83+
```js
84+
const { UnifiedWebpackPluginV5 } = require('weapp-tailwindcss/webpack')
85+
86+
// config/index.[jt]s
87+
module.exports = {
88+
mini: {
89+
webpackChain(chain) {
90+
chain.merge({
91+
plugin: {
92+
install: {
93+
plugin: UnifiedWebpackPluginV5,
94+
args: [{ rem2rpx: true }],
95+
},
96+
},
97+
})
98+
},
99+
},
100+
}
101+
```
102+
103+
### taro vite
104+
105+
```ts
106+
import type { Plugin } from 'vite'
107+
import tailwindcss from 'tailwindcss'
108+
import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'
109+
110+
export default {
111+
compiler: {
112+
type: 'vite',
113+
vitePlugins: [
114+
{
115+
name: 'postcss-config-loader-plugin',
116+
config(config: { css?: { postcss?: { plugins?: unknown[] } } }) {
117+
if (typeof config.css?.postcss === 'object') {
118+
config.css?.postcss.plugins?.unshift(tailwindcss())
119+
}
120+
},
121+
},
122+
uvtw({
123+
rem2rpx: true,
124+
injectAdditionalCssVarScope: true,
125+
disabled: process.env.TARO_ENV === 'h5',
126+
}),
127+
] as Plugin[],
128+
},
129+
}
130+
```
131+
132+
### uni-app x / 原生小程序
133+
134+
- `uni-app x` 优先走官方 `vite + weapp-tailwindcss/vite` 方案
135+
- 原生小程序优先引导到官方模板(`gulp` / `webpack`)后再增量改动
136+
137+
## 5. 多端项目策略
138+
139+
1. 小程序优先时再开启 `rem2rpx/px2rpx`
140+
2.`H5` 构建禁用小程序转译插件
141+
3. 样式入口统一管理,避免端间配置漂移
142+
143+
## 6. 最小验证清单
144+
145+
1. 启动开发构建并确认无报错
146+
2. 验证基础工具类(如 `flex`, `px-4`
147+
3. 验证任意值(如 `w-[22rpx]`, `text-[length:22rpx]`
148+
4. 验证变体/伪类(如 `hover:`, `after:`
149+
5. 产物检查:确认 `weapp-tw patch` 已执行过

skills/weapp-tailwindcss/references/tailwind-writing-best-practices.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- 必须动态时,使用“完整字面量枚举”,不要拼半截 token。
1818
- 动态组合统一经过 `cn``clsx + twMerge`)或 `cva/tv`
1919
- 小程序项目默认保留 `postinstall: "weapp-tw patch"`
20+
- `JS` 转译遵循 `classNameSet` 精确命中:不要依赖“看起来像 Tailwind”的启发式字符串拼接。
2021

2122
## 3. 推荐写法与反例
2223

0 commit comments

Comments
 (0)