Skip to content

Commit 36455dd

Browse files
committed
docs: update
1 parent 6cd1185 commit 36455dd

File tree

8 files changed

+326
-5
lines changed

8 files changed

+326
-5
lines changed

website/content/en/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
'patch': '1.Patch',
77
'mangle': '2.Mangle',
88
'config': '3.Config',
9+
'migration': 'Migration',
910
'recommend': {
1011
display: 'hidden',
1112
},

website/content/en/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Tailwind CSS makes it easy to build interfaces, but its utility classes are just
1414
- `unplugin-tailwindcss-mangle` reads the refreshed class list and supports Vite, Webpack, Rollup, Esbuild, and Nuxt 3.
1515

1616
<Callout type="info">
17-
Upgrading from v7.x? Follow the <a href="https://github.com/icebreaker/tailwindcss-mangle/blob/main/packages/tailwindcss-patch/MIGRATION.md" target="_blank" rel="noreferrer">migration guide</a> for a painless transition.
17+
Upgrading from v7.x? Follow the <a href="./migration">migration guide</a> for a painless transition.
1818
</Callout>
1919

2020
## Two-step workflow

website/content/en/migration.mdx

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { Callout } from 'nextra/components'
2+
3+
# Migration · v7 → v8
4+
5+
`[email protected]` refactors the extraction engine, introduces typed option objects, and streamlines configuration sharing across the toolchain. This guide walks you through upgrading an existing v7 setup—CLI, configs, and bundler plugins—without losing backwards compatibility.
6+
7+
<Callout type="info">
8+
Legacy configs still work. You can migrate incrementally by adding new fields while keeping the historical `patch`/`cache` structure.
9+
</Callout>
10+
11+
## 1. Update dependencies
12+
13+
```sh npm2yarn
14+
npm i -D tailwindcss-patch@^8 unplugin-tailwindcss-mangle@latest @tailwindcss-mangle/config@latest @tailwindcss-mangle/core@latest
15+
```
16+
17+
- The patch package ships the new API surface.
18+
- `unplugin-tailwindcss-mangle` consumes the refreshed class inventory and honours the shared config defaults.
19+
- `@tailwindcss-mangle/config` normalises both legacy and modern shapes for CLI and plugin consumers.
20+
21+
## 2. Review imports
22+
23+
The package layout now exposes purpose-specific entry points:
24+
25+
| v7 path | v8 replacement |
26+
| --- | --- |
27+
| `tailwindcss-patch/core/**` | `tailwindcss-patch/api/**`, `tailwindcss-patch/cache/**`, `tailwindcss-patch/runtime/**`, etc. |
28+
| `CacheManager` | `CacheStore` |
29+
| `processTailwindcss` | `runTailwindBuild` |
30+
31+
Update manual imports accordingly:
32+
33+
```ts
34+
import { TailwindcssPatcher } from 'tailwindcss-patch'
35+
import { CacheStore } from 'tailwindcss-patch/cache/store'
36+
import { applyTailwindPatches } from 'tailwindcss-patch/patching/patch-runner'
37+
```
38+
39+
## 3. Embrace the unified options object
40+
41+
The constructor now accepts a single `TailwindcssPatchOptions` object. Passing a legacy object with `patch`/`cache` still works—the runtime calls `fromLegacyOptions()` internally.
42+
43+
```ts
44+
// Legacy shape (still accepted)
45+
new TailwindcssPatcher({
46+
patch: {
47+
output: { filename: '.tw-patch/tw-class-list.json', loose: true },
48+
tailwindcss: { version: 3, v3: { cwd, config } },
49+
applyPatches: { extendLengthUnits: true },
50+
},
51+
})
52+
53+
// Recommended v8 shape
54+
new TailwindcssPatcher({
55+
overwrite: true,
56+
cache: {
57+
enabled: true,
58+
dir: '.tw-patch/cache',
59+
strategy: 'merge',
60+
},
61+
output: {
62+
file: '.tw-patch/tw-class-list.json',
63+
format: 'json',
64+
removeUniversalSelector: true,
65+
},
66+
features: {
67+
exposeContext: { refProperty: 'runtimeContexts' },
68+
extendLengthUnits: { units: ['rpx'] },
69+
},
70+
tailwind: {
71+
version: 4,
72+
v4: {
73+
base: './src',
74+
cssEntries: ['dist/tailwind.css'],
75+
},
76+
},
77+
})
78+
```
79+
80+
When migrating configs, add the new fields gradually:
81+
82+
- `output.format` (`json` or `lines`)
83+
- `output.pretty` (indentation or `false`)
84+
- `tailwind.v4.cssEntries` / `tailwind.v4.sources`
85+
- `features.extendLengthUnits` with shared options for Tailwind v3 and v4
86+
87+
## 4. Refresh CLI usage
88+
89+
`tw-patch install` and `tw-patch extract` keep their names but gained quality-of-life flags:
90+
91+
| Flag | Description |
92+
| --- | --- |
93+
| `--output <file>` | Override the generated class list target. |
94+
| `--format <json|lines>` | Emit JSON (default) or newline-delimited text. |
95+
| `--css <file>` | Provide Tailwind v4 CSS entry files. Repeat for multiple entries. |
96+
| `--no-write` | Skip writing to disk, returning the class list to the caller. |
97+
98+
Configuration is resolved from `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Existing `tailwindcss-mangle.config.ts` files are still picked up.
99+
100+
## 5. Cache strategy changes
101+
102+
`CacheStore` replaces `CacheManager` and unifies async behaviour:
103+
104+
```ts
105+
const cache = new CacheStore(options.cache)
106+
await cache.write(new Set(['text-lg']))
107+
const values = await cache.read()
108+
```
109+
110+
- `cache.strategy` now accepts `merge` (default) or `overwrite`.
111+
- `cache.enabled` can be toggled globally or per command via overrides.
112+
- Invalid JSON files are purged automatically to avoid silent failures.
113+
114+
## 6. Plugin & runtime alignment
115+
116+
`@tailwindcss-mangle/config` feeds both the CLI and `unplugin-tailwindcss-mangle`. Ensure your config exposes:
117+
118+
- `patch.output.filename` (or the new `output.file`)
119+
- `patch.applyPatches.extendLengthUnits` if you previously relied on the boolean flag
120+
- `mangle.classListPath` pointing at the generated `.tw-patch/tw-class-list.json`
121+
- `mangle.classMapOutput` if you need before/after maps for auditing
122+
123+
In bundlers, the minimal setup looks like:
124+
125+
```ts
126+
import tailwindcssMangle from 'unplugin-tailwindcss-mangle/vite'
127+
128+
export default defineConfig({
129+
plugins: [
130+
tailwindcssMangle({
131+
classListPath: '.tw-patch/tw-class-list.json',
132+
}),
133+
],
134+
})
135+
```
136+
137+
Nuxt 3 users should also set `experimental.inlineSSRStyles = false` so Vite emits CSS for scanning.
138+
139+
## 7. Tailwind v4 projects
140+
141+
Version 8.0 introduces native Tailwind v4 support:
142+
143+
- Provide CSS entry files via `tailwind.v4.cssEntries`.
144+
- Define content sources through `tailwind.v4.sources` (defaults to `**/*` under `base`).
145+
- Use the new `--css` CLI flag when extracting from monorepos that emit multiple CSS bundles.
146+
147+
## 8. Upgrade checklist
148+
149+
1. Update dependencies (`tailwindcss-patch`, `unplugin-tailwindcss-mangle`, shared packages).
150+
2. Regenerate or tweak `tailwindcss-patch.config.ts`, adding new `output` and `tailwind.v4` fields as needed.
151+
3. Adjust custom imports to the new module folders.
152+
4. Verify CLI scripts and CI pipelines with the refreshed flags.
153+
5. Clear stale caches if necessary (`pnpm script:clean`) and rerun `tw-patch extract`.
154+
6. Run your bundler build and confirm class names are rewritten as expected.
155+
7. (Optional) Enable `classMapOutput` to audit mappings during the first migration run.
156+
157+
## Need help?
158+
159+
- Compare against the legacy docs in your repository history.
160+
- Open an issue with reproduction steps if you hit a regression—we track migration feedback closely.

website/content/en/patch.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Callout } from 'nextra/components'
1212
- Refreshed CLI with clearer logging plus new `extract` flags (`--output`, `--format`, `--css`, `--no-write`) for automation.
1313

1414
<Callout type="info">
15-
Need upgrade guidance? See the <a href="https://github.com/icebreaker/tailwindcss-mangle/blob/main/packages/tailwindcss-patch/MIGRATION.md" target="_blank" rel="noreferrer">migration guide</a> for a step-by-step checklist from v7.x.
15+
Need upgrade guidance? See the <a href="./migration">migration guide</a> for a step-by-step checklist from v7.x.
1616
</Callout>
1717

1818
## Installation

website/content/zh/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
'patch': '1.Patch',
77
'mangle': '2.Mangle',
88
'config': '3.Config',
9+
'migration': '迁移指南',
910
'recommend': {
1011
display: 'hidden',
1112
},

website/content/zh/index.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Callout } from 'nextra/components'
1414
- `unplugin-tailwindcss-mangle` 读取最新的类名清单,并支持 Vite、Webpack、Rollup、Esbuild 与 Nuxt 3。
1515

1616
<Callout type="info">
17-
从 v7.x 升级?请参考 <a href="https://github.com/icebreaker/tailwindcss-mangle/blob/main/packages/tailwindcss-patch/MIGRATION.md" target="_blank" rel="noreferrer">迁移指南</a>,按步骤平滑过渡。
17+
从 v7.x 升级?请参考 <a href="./migration">迁移指南</a>,按步骤平滑过渡。
1818
</Callout>
1919

2020
## 两步工作流
@@ -46,4 +46,3 @@ npx tw-patch extract
4646
- `unplugin-tailwindcss-mangle` —— 读取类名清单,在打包阶段重写匹配的类名。
4747
- `@tailwindcss-mangle/config` —— 统一加载并标准化旧版与新版配置。
4848
- `@tailwindcss-mangle/shared` —— 内置类名生成、过滤及通用正则等辅助方法。
49-

website/content/zh/migration.mdx

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { Callout } from 'nextra/components'
2+
3+
# 迁移指南 · v7 → v8
4+
5+
`[email protected]` 彻底重构了提取引擎,引入统一的类型化配置对象,并让 CLI 与插件共享同一套默认值。本文将帮助你从 v7 升级:涵盖命令行、配置文件以及各类构建插件。
6+
7+
<Callout type="info">
8+
旧版配置仍然有效。你可以在保留 `patch`/`cache` 结构的同时,逐步补充新的字段。
9+
</Callout>
10+
11+
## 1. 升级依赖
12+
13+
```sh npm2yarn
14+
npm i -D tailwindcss-patch@^8 unplugin-tailwindcss-mangle@latest @tailwindcss-mangle/config@latest @tailwindcss-mangle/core@latest
15+
```
16+
17+
- `tailwindcss-patch` 提供新的 API 与提取能力。
18+
- `unplugin-tailwindcss-mangle` 会读取刷新后的类名清单,并继承共享配置。
19+
- `@tailwindcss-mangle/config` 负责在 CLI 与插件之间归一化旧/新配置。
20+
21+
## 2. 检查导入路径
22+
23+
现在的包结构按职责拆分:
24+
25+
| v7 路径 | v8 替代 |
26+
| --- | --- |
27+
| `tailwindcss-patch/core/**` | `tailwindcss-patch/api/**``tailwindcss-patch/cache/**``tailwindcss-patch/runtime/**`|
28+
| `CacheManager` | `CacheStore` |
29+
| `processTailwindcss` | `runTailwindBuild` |
30+
31+
相应地更新手写导入:
32+
33+
```ts
34+
import { TailwindcssPatcher } from 'tailwindcss-patch'
35+
import { CacheStore } from 'tailwindcss-patch/cache/store'
36+
import { applyTailwindPatches } from 'tailwindcss-patch/patching/patch-runner'
37+
```
38+
39+
## 3. 采用统一配置对象
40+
41+
构造函数现在接受一个 `TailwindcssPatchOptions` 对象。若传入包含 `patch` / `cache` 的旧结构,运行时会自动调用 `fromLegacyOptions()`
42+
43+
```ts
44+
// 旧结构(仍然受支持)
45+
new TailwindcssPatcher({
46+
patch: {
47+
output: { filename: '.tw-patch/tw-class-list.json', loose: true },
48+
tailwindcss: { version: 3, v3: { cwd, config } },
49+
applyPatches: { extendLengthUnits: true },
50+
},
51+
})
52+
53+
// 推荐的 v8 结构
54+
new TailwindcssPatcher({
55+
overwrite: true,
56+
cache: {
57+
enabled: true,
58+
dir: '.tw-patch/cache',
59+
strategy: 'merge',
60+
},
61+
output: {
62+
file: '.tw-patch/tw-class-list.json',
63+
format: 'json',
64+
removeUniversalSelector: true,
65+
},
66+
features: {
67+
exposeContext: { refProperty: 'runtimeContexts' },
68+
extendLengthUnits: { units: ['rpx'] },
69+
},
70+
tailwind: {
71+
version: 4,
72+
v4: {
73+
base: './src',
74+
cssEntries: ['dist/tailwind.css'],
75+
},
76+
},
77+
})
78+
```
79+
80+
在迁移配置文件时,可以逐步补充以下新字段:
81+
82+
- `output.format``json``lines`
83+
- `output.pretty`(缩进空格或 `false`
84+
- `tailwind.v4.cssEntries` / `tailwind.v4.sources`
85+
- `features.extendLengthUnits` —— 针对 v3/v4 共用的长度单位补丁
86+
87+
## 4. 更新 CLI 用法
88+
89+
`tw-patch install``tw-patch extract` 依旧可用,但新增了一些实用参数:
90+
91+
| 参数 | 说明 |
92+
| --- | --- |
93+
| `--output <file>` | 指定生成类名清单的文件位置。 |
94+
| `--format <json|lines>` | 切换 JSON(默认)或按行文本。 |
95+
| `--css <file>` | 为 Tailwind v4 提供 CSS 入口,可重复设置多个文件。 |
96+
| `--no-write` | 跳过写入磁盘,仅返回集合。 |
97+
98+
命令会通过 `@tailwindcss-mangle/config` 加载 `tailwindcss-patch.config.ts`。若仍使用旧的 `tailwindcss-mangle.config.ts`,同样会被识别。
99+
100+
## 5. 缓存策略调整
101+
102+
`CacheStore` 取代 `CacheManager`,并统一了异步行为:
103+
104+
```ts
105+
const cache = new CacheStore(options.cache)
106+
await cache.write(new Set(['text-lg']))
107+
const values = await cache.read()
108+
```
109+
110+
- `cache.strategy` 支持 `merge`(默认)与 `overwrite`
111+
- 可以在配置或命令覆盖中开启/关闭 `cache.enabled`
112+
- 如果缓存 JSON 损坏,会自动清理以避免静默失败。
113+
114+
## 6. 插件与运行时对齐
115+
116+
`@tailwindcss-mangle/config` 同时服务于 CLI 与 `unplugin-tailwindcss-mangle`。请确认配置中包括:
117+
118+
- `patch.output.filename`(或新版的 `output.file`
119+
- `patch.applyPatches.extendLengthUnits` —— 若之前使用布尔值,需要改为对象配置
120+
- `mangle.classListPath` 指向 `.tw-patch/tw-class-list.json`
121+
- `mangle.classMapOutput` —— 若需要输出类名映射以便审计
122+
123+
在构建工具中最小化的配置示例如下:
124+
125+
```ts
126+
import tailwindcssMangle from 'unplugin-tailwindcss-mangle/vite'
127+
128+
export default defineConfig({
129+
plugins: [
130+
tailwindcssMangle({
131+
classListPath: '.tw-patch/tw-class-list.json',
132+
}),
133+
],
134+
})
135+
```
136+
137+
若使用 Nuxt 3,记得设置 `experimental.inlineSSRStyles = false`,以便 Vite 输出 CSS 供扫描。
138+
139+
## 7. 面向 Tailwind v4
140+
141+
8.0 版本原生支持 Tailwind v4:
142+
143+
- 通过 `tailwind.v4.cssEntries` 声明 CSS 入口文件。
144+
- 可使用 `tailwind.v4.sources` 自定义内容扫描路径(默认在 `base` 下匹配 `**/*`)。
145+
- 当存在多套 CSS 产物时,可在 CLI 中使用 `--css` 指定要扫描的输出。
146+
147+
## 8. 升级检查清单
148+
149+
1. 升级依赖(`tailwindcss-patch``unplugin-tailwindcss-mangle` 以及共享包)。
150+
2. 调整或重建 `tailwindcss-patch.config.ts`,按需补充新的 `output``tailwind.v4` 字段。
151+
3. 更新自定义导入路径,指向新的模块目录。
152+
4. 校准 CLI 与 CI 脚本,验证新增参数是否需要覆盖。
153+
5. 必要时清理缓存(`pnpm script:clean`),重新执行 `tw-patch extract`
154+
6. 运行构建流程,确认类名按预期被重写。
155+
7. (可选)启用 `classMapOutput`,在首次迁移时审查映射结果。
156+
157+
## 需要帮助?
158+
159+
- 可对照仓库旧文档,确认差异。
160+
- 如遇兼容性问题,请携带复现步骤提交 Issue,我们会优先跟进迁移反馈。

website/content/zh/patch.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Callout } from 'nextra/components'
1212
- 全新的 CLI 日志体验,并为 `extract` 命令带来 `--output``--format``--css``--no-write` 等新选项。
1313

1414
<Callout type="info">
15-
需要从 7.x 升级?查看 <a href="https://github.com/icebreaker/tailwindcss-mangle/blob/main/packages/tailwindcss-patch/MIGRATION.md" target="_blank" rel="noreferrer">迁移指南</a> 获取逐步检查清单。
15+
需要从 7.x 升级?查看 <a href="./migration">迁移指南</a> 获取逐步检查清单。
1616
</Callout>
1717

1818
## 安装

0 commit comments

Comments
 (0)