Skip to content

Commit 58a4fb4

Browse files
committed
doc: fix tailwindcss-patch typo
1 parent ccae548 commit 58a4fb4

File tree

3 files changed

+147
-14
lines changed

3 files changed

+147
-14
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# 使用 `tailwindcss-patch@2` 来提取你的类名吧
2+
3+
`tailwindcss-patch` 是一个 `tailwindcss` 生态的扩展项目。也是 [`tailwindcss-mangle`](https://github.com/sonofmagic/tailwindcss-mangle) 项目重要的组成部分。
4+
5+
最近我发布了 `tailwindcss-patch``2.x` 版本,相比 `1.x` 版本,主要添加了一个配置文件读取和工具类名提取额功能。
6+
7+
让我们来看看怎么使用它吧。
8+
9+
## 安装
10+
11+
选择你喜欢的包管理器
12+
13+
```sh
14+
<yarn|npm|pnpm> add -D tailwindcss-patch
15+
```
16+
17+
1.`tailwindcss` 打补丁
18+
19+
```sh
20+
npx tw-patch install
21+
```
22+
23+
1.`npm``prepare` `hook` 里加入指令
24+
25+
`package.json`
26+
27+
```json
28+
{
29+
/* ... */
30+
"scripts": {
31+
"prepare": "tw-patch install"
32+
}
33+
}
34+
```
35+
36+
## 使用方式
37+
38+
## 命令行 Cli
39+
40+
### 开始提取吧
41+
42+
```sh
43+
npx tw-patch extract
44+
```
45+
46+
默认情况下,执行成功后会有一个 `json` 文件 `.tw-patch/tw-class-list.json` 在你的项目中出现。
47+
48+
当然,你可以通过配置文件 `tailwindcss-mangle.config.ts` 来自定义这个行为。
49+
50+
## Nodejs API 的方式来使用
51+
52+
```js
53+
import { TailwindcssPatcher } from 'tailwindcss-patch'
54+
55+
const twPatcher = new TailwindcssPatcher(/* options */)
56+
// do patch
57+
twPatcher.patch()
58+
// get all contexts at runtime
59+
twPatcher.getContexts()
60+
// get all class generated by tailwindcss utilities
61+
twPatcher.getClassSet()
62+
```
63+
64+
## 配置
65+
66+
### 初始化
67+
68+
```sh
69+
npx tw-patch init
70+
```
71+
72+
这样在你的当前的 `cwd` 中就会出现一个 `tailwindcss-mangle.config.ts` 文件:
73+
74+
```ts
75+
import { defineConfig } from 'tailwindcss-patch'
76+
77+
export default defineConfig({})
78+
```
79+
80+
你可以通过 `patch` 字段来自定义它的行为:
81+
82+
```ts
83+
import { defineConfig } from 'tailwindcss-patch'
84+
85+
export default defineConfig({
86+
patch: {
87+
output: {
88+
filename: 'xxx.json',
89+
loose: true,
90+
removeUniversalSelector: true
91+
},
92+
tailwindcss: {
93+
config: 'path/to/your-tailwind.config.js',
94+
cwd: 'project/cwd'
95+
}
96+
}
97+
})
98+
```

packages/tailwindcss-patch/README.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# tailwindcss-patch
22

3+
\[[中文(zh-cn)](./README-cn.md)\]
4+
35
get tailwindcss context at runtime ! extract all classes into file!
46

57
- [tailwindcss-patch](#tailwindcss-patch)
68
- [Setup](#setup)
79
- [Usage](#usage)
810
- [Cli](#cli)
9-
- [Init Config File](#init-config-file)
1011
- [Extract all class into a json](#extract-all-class-into-a-json)
11-
- [Nodejs](#nodejs)
12+
- [Nodejs API](#nodejs-api)
13+
- [Config](#config)
14+
- [Init Config File](#init-config-file)
1215
- [Migration form v1 to v2](#migration-form-v1-to-v2)
1316
- [0. cli command change](#0-cli-command-change)
1417
- [1. default remove `*` in json array result](#1-default-remove--in-json-array-result)
@@ -20,7 +23,7 @@ get tailwindcss context at runtime ! extract all classes into file!
2023
1. Install package
2124

2225
```sh
23-
<yarn|npm|pnpm> add -D ts-patch
26+
<yarn|npm|pnpm> add -D tailwindcss-patch
2427
```
2528

2629
2. Patch tailwindcss
@@ -46,36 +49,68 @@ npx tw-patch install
4649

4750
## Cli
4851

49-
### Init Config File
50-
51-
```sh
52-
tw-patch init
53-
```
54-
55-
Then there will be a ts file called `tailwindcss-mangle.config.ts` exist in your `cwd`.
56-
5752
### Extract all class into a json
5853

5954
```sh
60-
tw-patch extract
55+
npx tw-patch extract
6156
```
6257

6358
default there will be a json in `.tw-patch/tw-class-list.json` in your project.
6459

6560
you can custom this behavior by config `tailwindcss-mangle.config.ts`
6661

67-
### Nodejs
62+
## Nodejs API
6863

6964
```js
7065
import { TailwindcssPatcher } from 'tailwindcss-patch'
7166

7267
const twPatcher = new TailwindcssPatcher(/* options */)
68+
// do patch
69+
twPatcher.patch()
7370
// get all contexts at runtime
7471
twPatcher.getContexts()
7572
// get all class generated by tailwindcss utilities
7673
twPatcher.getClassSet()
7774
```
7875

76+
## Config
77+
78+
### Init Config File
79+
80+
```sh
81+
npx tw-patch init
82+
```
83+
84+
Then there will be a ts file called `tailwindcss-mangle.config.ts` exist in your `cwd`.
85+
86+
The config as follows:
87+
88+
```ts
89+
import { defineConfig } from 'tailwindcss-patch'
90+
91+
export default defineConfig({})
92+
```
93+
94+
you can custom `tw-patch` behavior by `patch` option:
95+
96+
```ts
97+
import { defineConfig } from 'tailwindcss-patch'
98+
99+
export default defineConfig({
100+
patch: {
101+
output: {
102+
filename: 'xxx.json',
103+
loose: true,
104+
removeUniversalSelector: true
105+
},
106+
tailwindcss: {
107+
config: 'path/to/your-tailwind.config.js',
108+
cwd: 'project/cwd'
109+
}
110+
}
111+
})
112+
```
113+
79114
## Migration form v1 to v2
80115

81116
### 0. cli command change

packages/tailwindcss-patch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailwindcss-patch",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "patch tailwindcss for exposing context and extract classes",
55
"main": "./dist/index.cjs",
66
"types": "./dist/index.d.ts",

0 commit comments

Comments
 (0)