tailwindcss-patch 7.1.6 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,121 +1,135 @@
1
1
  # tailwindcss-patch
2
2
 
3
- get tailwindcss context at runtime ! extract all classes into file!
3
+ Modern tooling to patch Tailwind CSS, capture runtime contexts, and materialise every class that Tailwind can generate. The package now ships with a redesigned architecture focused on clarity, predictable configuration, and first-class Tailwind v4 support.
4
4
 
5
- - [tailwindcss-patch](#tailwindcss-patch)
6
- - [Docs](#docs)
7
- - [Setup](#setup)
8
- - [Usage](#usage)
9
- - [Cli](#cli)
10
- - [Extract all class into a json](#extract-all-class-into-a-json)
11
- - [Nodejs API](#nodejs-api)
12
- - [Config](#config)
13
- - [Init Config File](#init-config-file)
14
- - [What's next?](#whats-next)
5
+ - Export runtime contexts for Tailwind v2/v3 without editing source files manually.
6
+ - Traverse Tailwind v4 projects by scanning CSS outputs and content sources.
7
+ - Write class inventories to disk or keep them in memory for tooling integrations.
8
+ - Control caching, filtering, and custom unit extensions from a single, typed entrypoint.
15
9
 
16
- > Nodejs version should >= `16.6.0`
10
+ ## Installation
17
11
 
18
- ## Docs
19
-
20
- [mangle.icebreaker.top](https://mangle.icebreaker.top)
21
-
22
- ## Setup
23
-
24
- 1. Install package
25
-
26
- ```sh
27
- <yarn|npm|pnpm> add -D tailwindcss-patch
28
- ```
29
-
30
- 2. Patch tailwindcss
31
-
32
- ```sh
33
- npx tw-patch install
12
+ ```bash
13
+ pnpm add -D tailwindcss-patch
14
+ pnpm dlx tw-patch install
34
15
  ```
35
16
 
36
- 3. Add `prepare` script (keeps patch persisted after npm install)
37
-
38
- `package.json`
17
+ Keep the patch applied after installs by adding a `prepare` hook:
39
18
 
40
19
  ```json
41
20
  {
42
- /* ... */
43
21
  "scripts": {
44
22
  "prepare": "tw-patch install"
45
23
  }
46
24
  }
47
25
  ```
48
26
 
49
- ## Usage
27
+ ## CLI Usage
50
28
 
51
- ## Cli
29
+ Run the CLI through `tw-patch` (or `tailwindcss-patch`) from your project root.
52
30
 
53
- ### Extract all class into a json
31
+ ```bash
32
+ # Apply runtime patches to the local Tailwind installation
33
+ pnpm dlx tw-patch install
54
34
 
55
- ```sh
56
- npx tw-patch extract
35
+ # Extract all classes into the configured output file
36
+ pnpm dlx tw-patch extract
57
37
  ```
58
38
 
59
- default there will be a json in `.tw-patch/tw-class-list.json` in your project.
60
-
61
- you can custom this behavior by config `tailwindcss-mangle.config.ts`
39
+ ### Extract options
62
40
 
63
- ## Nodejs API
41
+ | Flag | Description |
42
+ | ------------------------ | ---------------------------------------------------------------- |
43
+ | `--cwd <dir>` | Use a different working directory when loading configuration. |
44
+ | `--output <file>` | Override the target file for the generated class list. |
45
+ | `--format <json\|lines>` | Switch between JSON output (default) and newline-delimited text. |
46
+ | `--css <file>` | Provide a CSS entry file when working with Tailwind v4 projects. |
47
+ | `--no-write` | Skip writing to disk and only return the collected classes. |
64
48
 
65
- ```js
66
- import { TailwindcssPatcher } from 'tailwindcss-patch'
49
+ The CLI loads `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Legacy configs continue to work; see the [migration guide](./MIGRATION.md) for hints on the new fields.
67
50
 
68
- const twPatcher = new TailwindcssPatcher(/* options */)
69
- // do patch
70
- twPatcher.patch()
71
- // get all contexts at runtime
72
- twPatcher.getContexts()
73
- // get all class generated by tailwindcss utilities
74
- twPatcher.getClassSet()
75
- ```
51
+ ## Programmatic API
76
52
 
77
- ## Config
53
+ ```ts
54
+ import { TailwindcssPatcher } from 'tailwindcss-patch'
78
55
 
79
- ### Init Config File
56
+ const patcher = new TailwindcssPatcher({
57
+ overwrite: true,
58
+ cache: {
59
+ enabled: true,
60
+ dir: '.tw-patch/cache',
61
+ strategy: 'merge',
62
+ },
63
+ output: {
64
+ file: '.tw-patch/tw-class-list.json',
65
+ format: 'json',
66
+ },
67
+ features: {
68
+ exposeContext: { refProperty: 'runtimeContexts' },
69
+ extendLengthUnits: {
70
+ units: ['rpx'],
71
+ },
72
+ },
73
+ tailwind: {
74
+ version: 4,
75
+ v4: {
76
+ base: './src',
77
+ cssEntries: ['dist/tailwind.css'],
78
+ },
79
+ },
80
+ })
80
81
 
81
- ```sh
82
- npx tw-patch init
82
+ await patcher.patch()
83
+ const { classList, filename } = await patcher.extract()
83
84
  ```
84
85
 
85
- Then there will be a ts file called `tailwindcss-mangle.config.ts` exist in your `cwd`.
86
+ The constructor accepts either the new object shown above or the historical `patch`/`cache` shape. Conversions happen internally so existing configs remain backwards compatible.
86
87
 
87
- The config as follows:
88
+ ### Helper utilities
88
89
 
89
- ```ts
90
- import { defineConfig } from 'tailwindcss-patch'
90
+ - `normalizeOptions` – normalise raw user input to the runtime shape.
91
+ - `CacheStore` read/write class caches respecting merge or overwrite semantics.
92
+ - `extractValidCandidates` – scan Tailwind v4 CSS/content sources with the Tailwind Oxide scanner.
93
+ - `runTailwindBuild` – run the Tailwind PostCSS plugin for v2/v3 projects to prime runtime contexts.
91
94
 
92
- export default defineConfig({})
93
- ```
95
+ All helpers are exported from the package root for direct consumption in custom tooling.
94
96
 
95
- you can custom `tw-patch` behavior by `patch` option:
97
+ ## Configuration Example
96
98
 
97
99
  ```ts
100
+ // tailwindcss-patch.config.ts
98
101
  import { defineConfig } from 'tailwindcss-patch'
99
102
 
100
103
  export default defineConfig({
101
104
  patch: {
102
105
  output: {
103
- filename: 'xxx.json',
104
- loose: true,
105
- removeUniversalSelector: true
106
+ filename: '.tw-patch/tw-class-list.json',
107
+ removeUniversalSelector: true,
108
+ format: 'json',
106
109
  },
107
110
  tailwindcss: {
108
- config: 'path/to/your-tailwind.config.js',
109
- cwd: 'project/cwd'
110
- }
111
- }
111
+ version: 4,
112
+ v4: {
113
+ cssEntries: ['dist/tailwind.css'],
114
+ sources: [{ base: 'src', pattern: '**/*.{html,tsx}', negated: false }],
115
+ },
116
+ },
117
+ applyPatches: {
118
+ exportContext: true,
119
+ extendLengthUnits: {
120
+ units: ['rpx'],
121
+ },
122
+ },
123
+ },
112
124
  })
113
125
  ```
114
126
 
115
- ## What's next?
127
+ Even though `defineConfig` still exposes the historical shape, every new option is supported and will be normalised automatically.
128
+
129
+ ## Migration
116
130
 
117
- At the moment I just extracted all the tool classes to actually get the context of `tailwindcss` to analyze. You can add more functionality to this project by giving me `issue` or `pr`.
131
+ Breaking changes, module moves, and upgrade paths are documented in [MIGRATION.md](./MIGRATION.md). Review it when updating from tailwindcss-patch v7.x or earlier.
118
132
 
119
- Of course, the extracted `JSON` isn't just for you to look at. You can analyze it, and I use it as a data file for my `tailwindcss-mangle`.
133
+ ## License
120
134
 
121
- The `tailwindcss-mangle` itself is an obfuscation tool to obfuscate the tools generated by `tailwindcss`, see the next article for more details on how to use it.
135
+ MIT © ice breaker