Skip to content

Commit 227496f

Browse files
committed
feat: release unplugin-tailwindcss-mangle 0.0.1
1 parent 4f144dc commit 227496f

File tree

5 files changed

+582
-128
lines changed

5 files changed

+582
-128
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
"jest": "^29.5.0",
2828
"only-allow": "^1.1.1",
2929
"prettier": "^2.8.7",
30-
"rollup": "^3.20.2",
30+
"rollup": "^3.20.6",
3131
"ts-jest": "^29.1.0",
3232
"ts-node": "^10.9.1",
33-
"turbo": "^1.9.0",
33+
"turbo": "^1.9.3",
3434
"typescript": "^5.0.4"
3535
},
3636
"engines": {
Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,96 @@
1-
# unplugin-tailwindcss-mangle (WIP)
1+
# unplugin-tailwindcss-mangle
2+
3+
mangle tailwindcss utilities plugin
4+
5+
> Now Support `vite` and `webpack`
6+
7+
- [unplugin-tailwindcss-mangle](#unplugin-tailwindcss-mangle)
8+
- [Features](#features)
9+
- [Usage](#usage)
10+
- [1. Install Package](#1-install-package)
11+
- [2. Run patch script](#2-run-patch-script)
12+
- [3. add `prepare` script in your `package.json`](#3-add-prepare-script-in-your-packagejson)
13+
- [4. register this plugin](#4-register-this-plugin)
14+
- [vite](#vite)
15+
- [webpack](#webpack)
16+
- [Notice](#notice)
17+
18+
## Features
19+
20+
```html
21+
<!-- before -->
22+
<div class="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex"></div>
23+
<!-- after -->
24+
<div class="tw-g tw-h tw-i tw-d tw-e tw-j tw-k tw-l"></div>
25+
```
26+
27+
## Usage
28+
29+
### 1. Install Package
30+
31+
```sh
32+
<npm|yarn|pnpm> i -D unplugin-tailwindcss-mangle tailwindcss-patch
33+
```
34+
35+
### 2. Run patch script
36+
37+
```sh
38+
npx tw-patch
39+
```
40+
41+
### 3. add `prepare` script in your `package.json`
42+
43+
```json
44+
"scripts": {
45+
"prepare": "tw-patch"
46+
},
47+
```
48+
49+
### 4. register this plugin
50+
51+
#### vite
52+
53+
```js
54+
// for example: vue vite project
55+
import { defineConfig } from 'vite'
56+
import vue from '@vitejs/plugin-vue'
57+
import utwm from 'unplugin-tailwindcss-mangle'
58+
// https://vitejs.dev/config/
59+
export default defineConfig({
60+
plugins: [vue(), utwm.vite()]
61+
})
62+
```
63+
64+
then run script:
65+
66+
```sh
67+
# generate bundle
68+
yarn build
69+
# preview
70+
yarn preview
71+
```
72+
73+
You will see all class was renamed to `tw-*`
74+
75+
#### webpack
76+
77+
```js
78+
import utwm from 'unplugin-tailwindcss-mangle'
79+
// use this webpack plugin
80+
utwm.webpack()
81+
```
82+
83+
## Notice
84+
85+
This plugin only transform those classes which name with `-` or `:`, like `w-32`, `before:h-[300px]`,`after:dark:via-[#0141ff]/40`. some classes like `flex`,`relative` will not be mangled.
86+
87+
because plugin will **traverse** all `html class attr` and `js StringLiteral` to find `utilities` generated by `tailwindcss`.
88+
89+
it's dangerous to mangle some `js StringLiteral` like:
90+
91+
```js
92+
const innerHTML = "i'm flex and relative and grid"
93+
document.body.innerHTML = innerHTML
94+
```
95+
96+
so only strings with `-` or `:` will be transformed.

packages/unplugin-tailwindcss-mangle/package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unplugin-tailwindcss-mangle",
3-
"version": "0.0.0",
4-
"description": "",
3+
"version": "0.0.1",
4+
"description": "mangle tailwindcss utilities class",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
77
"types": "./dist/index.d.ts",
@@ -53,7 +53,12 @@
5353
"files": [
5454
"dist"
5555
],
56-
"keywords": [],
56+
"keywords": [
57+
"tailwindcss",
58+
"utilities",
59+
"mangle",
60+
"class"
61+
],
5762
"author": "SonOfMagic <[email protected]>",
5863
"license": "MIT",
5964
"dependencies": {
@@ -64,9 +69,9 @@
6469
"acorn-walk": "^8.2.0",
6570
"escodegen": "^2.0.0",
6671
"parse5": "^7.1.2",
67-
"postcss": "^8.4.21",
72+
"postcss": "^8.4.22",
6873
"postcss-selector-parser": "^6.0.11",
69-
"semver": "^7.3.8",
74+
"semver": "^7.5.0",
7075
"tailwindcss-patch": "workspace:*",
7176
"unplugin": "^1.3.1"
7277
},
@@ -83,7 +88,7 @@
8388
"pkg-types": "^1.0.2",
8489
"tailwindcss": "^3.3.1",
8590
"tslib": "^2.5.0",
86-
"vite": "^4.2.0",
91+
"vite": "^4.2.2",
8792
"webpack": "^5.79.0"
8893
},
8994
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",

0 commit comments

Comments
 (0)