Skip to content

Commit e1354a2

Browse files
committed
feat: add --css [file] for tailwindcss@4 extract
1 parent 6716921 commit e1354a2

File tree

4 files changed

+177
-17
lines changed

4 files changed

+177
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
[
2+
"![color:red]/50",
3+
"!bg-[#0088cc]",
4+
"!bg-red-500",
5+
"!p",
6+
"!underline",
7+
"-inset-full",
8+
"[color:red]",
9+
"[color:red]/50",
10+
"[color:red]/50!",
11+
"[color:red]/[0.5]",
12+
"[color:red]/[0.5]!",
13+
"backdrop-filter",
14+
"basis-[32rpx]",
15+
"bg-(--spacing-0_5,var(--spacing-1_5,3rem))",
16+
"bg-[#0088cc]!",
17+
"bg-[#0088cc]/50",
18+
"bg-[#0088cc]/[0.5]",
19+
"bg-[#123456]",
20+
"bg-[#2f2f2f]",
21+
"bg-[#7d7ac2]",
22+
"bg-[-1px_-1px]",
23+
"bg-[no-repeat_url(/image_13.png)]",
24+
"bg-[url('https://xxx.webp')]",
25+
"bg-[var(--spacing)-1px]",
26+
"bg-[var(--spacing)_-_1px]",
27+
"bg-[var(--spacing-0_5,_var(--spacing-1_5,_3rem))]",
28+
"bg-blue-500",
29+
"bg-gradient-to-b",
30+
"bg-red-500",
31+
"bg-red-500!",
32+
"bg-red-500/50",
33+
"bg-red-500/[0.5]",
34+
"bg-size",
35+
"blur",
36+
"border-color",
37+
"bottom",
38+
"bottom-left",
39+
"bottom-right",
40+
"box-border",
41+
"brightness",
42+
"col-resize",
43+
"columns",
44+
"contain",
45+
"container",
46+
"content",
47+
"content-[\"hello_world\"]",
48+
"content-[\\\"hello_world\\\"]",
49+
"content-[____\"hello_world\"___]",
50+
"content-[____\\\"hello_world\\\"___]",
51+
"contents",
52+
"contrast",
53+
"cursor",
54+
"end",
55+
"fill",
56+
"filter",
57+
"flex",
58+
"font-bold",
59+
"font-palette",
60+
"from",
61+
"from-[#2f73f1]",
62+
"from-font",
63+
"gap",
64+
"grayscale",
65+
"h",
66+
"h-[12rpx]",
67+
"h-[30px]",
68+
"h-[45px]",
69+
"hidden",
70+
"hover:focus:text-white",
71+
"inset",
72+
"invert",
73+
"left",
74+
"left-bottom",
75+
"left-top",
76+
"list",
77+
"m",
78+
"m-[23.43rpx]",
79+
"max-h-[12rpx]",
80+
"max-w-[12rpx]",
81+
"md:text-[20px]",
82+
"me",
83+
"min-h-[12rpx]",
84+
"min-w-[12rpx]",
85+
"ms",
86+
"my",
87+
"object",
88+
"object-hash",
89+
"opacity",
90+
"order",
91+
"outline-color",
92+
"p",
93+
"p-[0.32rpx]",
94+
"p-[calc((100vw-theme(maxWidth.2xl))/2)]",
95+
"p-[calc((100vw-theme(maxWidth.2xl))_/_2)]",
96+
"p-[round(to-zero,1px)]",
97+
"pe",
98+
"placeholder",
99+
"pr",
100+
"pt",
101+
"px",
102+
"right",
103+
"right-bottom",
104+
"right-top",
105+
"rotate",
106+
"row-resize",
107+
"saturate",
108+
"scale",
109+
"sepia",
110+
"shadow",
111+
"size",
112+
"skew",
113+
"space-y-[12.0rpx]",
114+
"start",
115+
"stroke",
116+
"text",
117+
"text-(--x)",
118+
"text-3xl",
119+
"text-[#123456]",
120+
"text-[100px]",
121+
"text-[20px]",
122+
"text-[99px]",
123+
"text-[length:32rpx]",
124+
"text-decoration-color",
125+
"text-white",
126+
"text-xs",
127+
"to",
128+
"to-[#4bcefd]",
129+
"to-zero",
130+
"top",
131+
"top-left",
132+
"top-right",
133+
"top/",
134+
"transform",
135+
"translate",
136+
"underline",
137+
"underline!",
138+
"via",
139+
"w",
140+
"w-1/2",
141+
"w-[12rpx]",
142+
"w-[323px]",
143+
"w-resize",
144+
"z"
145+
]

packages/tailwindcss-patch/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'tailwindcss';

packages/tailwindcss-patch/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"build": "tsup",
4343
"test": "pnpm run patch && vitest run --coverage.enabled",
4444
"test:dev": "vitest",
45-
"patch": "tsx dev/bin.js install"
45+
"patch": "tsx dev/bin.js install",
46+
"r0": "tsx dev/bin.js extract",
47+
"r1": "tsx dev/bin.js extract --css index.css"
4648
},
4749
"publishConfig": {
4850
"access": "public",

packages/tailwindcss-patch/src/cli.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { PatchUserConfig } from '@tailwindcss-mangle/config'
12
import process from 'node:process'
23
import { CONFIG_NAME, getConfig, initConfig } from '@tailwindcss-mangle/config'
34
import { defuOverrideArray } from '@tailwindcss-mangle/shared'
@@ -25,22 +26,33 @@ cli.command('init').action(async () => {
2526
logger.success(`✨ ${CONFIG_NAME}.config.ts initialized!`)
2627
})
2728

28-
cli.command('extract').action(async () => {
29-
const { config } = await getConfig()
30-
if (config) {
31-
const twPatcher = new TailwindcssPatcher(
32-
{
33-
patch: defuOverrideArray(config.patch!, {
34-
resolve: {
35-
paths: [import.meta.url],
36-
},
37-
}),
38-
},
39-
)
40-
const p = await twPatcher.extract()
41-
p && logger.success(`✨ tailwindcss-patch extract success! file path: ${p.filename}, classList length: ${p.classList.length}`)
42-
}
43-
})
29+
cli.command('extract')
30+
.option('--css [file]', 'css file entries')
31+
.action(async (options) => {
32+
const { config } = await getConfig()
33+
const file = options.css as string
34+
if (config) {
35+
const twPatcher = new TailwindcssPatcher(
36+
{
37+
patch: defuOverrideArray(
38+
config.patch!,
39+
{
40+
resolve: {
41+
paths: [import.meta.url],
42+
},
43+
tailwindcss: {
44+
v4: {
45+
cssEntries: file ? [file] : undefined,
46+
},
47+
},
48+
} as Partial<PatchUserConfig>,
49+
),
50+
},
51+
)
52+
const p = await twPatcher.extract()
53+
p && logger.success(`✨ tailwindcss-patch extract success! file path: ${p.filename}, classList length: ${p.classList.length}`)
54+
}
55+
})
4456

4557
cli.help()
4658

0 commit comments

Comments
 (0)