2.2.3 • Published 3 months ago

tailwindcss-patch v2.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

tailwindcss-patch

[中文(zh-cn)]

get tailwindcss context at runtime ! extract all classes into file!

Nodejs version should >= 16.6.0

Setup

  1. Install package
<yarn|npm|pnpm> add -D tailwindcss-patch
  1. Patch tailwindcss
npx tw-patch install
  1. Add prepare script (keeps patch persisted after npm install)

package.json

{
  /* ... */
  "scripts": {
    "prepare": "tw-patch install"
  }
}

Usage

Cli

Extract all class into a json

npx tw-patch extract

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

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

Nodejs API

import { TailwindcssPatcher } from 'tailwindcss-patch'

const twPatcher = new TailwindcssPatcher(/* options */)
// do patch
twPatcher.patch()
// get all contexts at runtime
twPatcher.getContexts()
// get all class generated by tailwindcss utilities
twPatcher.getClassSet()

Config

Init Config File

npx tw-patch init

Then there will be a ts file called tailwindcss-mangle.config.ts exist in your cwd.

The config as follows:

import { defineConfig } from 'tailwindcss-patch'

export default defineConfig({})

you can custom tw-patch behavior by patch option:

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'
    }
  }
})

Migration form v1 to v2

0. cli command change

{
- "tw-patch"
+ "tw-patch install"
}

1. default remove * in json array result

[
- "*",
  "text-[99px]",
  "text-[100px]"
]

What's next?

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.

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.

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.

2.2.3

3 months ago

2.0.5-alpha.0

9 months ago

2.0.5-alpha.1

9 months ago

1.2.7

10 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

2.2.1

8 months ago

2.0.3

9 months ago

2.2.0

8 months ago

2.1.1

9 months ago

2.0.2

9 months ago

2.0.5

9 months ago

2.2.2

8 months ago

2.0.4

9 months ago

2.0.5-alpha.4

9 months ago

2.0.0-alpha.0

9 months ago

2.0.5-alpha.2

9 months ago

2.0.5-alpha.3

9 months ago

2.1.0

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.2.1

12 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.0-rc.2

1 year ago

1.1.0-rc.1

1 year ago

1.1.0-rc.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago