1. Patch
This step is to export the context extracted from your tailwindcss into a Json file.
Installation
Choose your preferred package manager for installation.
npm i -D tailwindcss-patchPatching
- Patch
tailwindcss
npx tw-patch installRegister npm hook
- Add the command to the
preparehook innpm
package.json
{
/* ... */
"scripts": {
"prepare": "tw-patch install"
}
}Usage
Command Line Interface (CLI)
Start Extracting
npx tw-patch extractBy default, a json file .tw-patch/tw-class-list.json will appear in your project upon successful execution.
Of course, you can customize this behavior through the configuration file
tailwindcss-mangle.config.ts.
Node.js API
import { TailwindcssPatcher } from 'tailwindcss-patch'
const twPatcher = new TailwindcssPatcher(/* options */)
// Perform patch action
twPatcher.patch()
// Get all contexts at runtime
twPatcher.getContexts()
// Get all classes generated by tailwindcss utilities
twPatcher.getClassSet()The core of this phase is to obtain the .tw-patch/tw-class-list.json file.
Once it is generated, we can proceed with our Mangle process.
Configuration
Initialization
npx tw-patch initThis will create a tailwindcss-mangle.config.ts file in your current working directory (cwd):
import { defineConfig } from 'tailwindcss-patch'
export default defineConfig({})You can customize its behavior through the patch field:
import { defineConfig } from 'tailwindcss-patch'
export default defineConfig({
patch: {
output: {
filename: 'xxx.json',
loose: true,
removeUniversalSelector: true
},
tailwindcss: {
config: 'path/to/your/tailwind.config.js',
cwd: 'project/cwd'
}
}
})Last updated on