Skip to content

Commit 93114ba

Browse files
committed
docs: update mdx
1 parent b5c60b1 commit 93114ba

File tree

17 files changed

+526
-453
lines changed

17 files changed

+526
-453
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@commitlint/config-conventional": "^19.6.0",
3939
"@commitlint/prompt-cli": "^19.6.0",
4040
"@commitlint/types": "^19.5.0",
41-
"@icebreakers/eslint-config": "^0.7.2",
41+
"@icebreakers/eslint-config": "^0.7.3",
4242
"@icebreakers/monorepo": "^0.6.15",
4343
"@icebreakers/stylelint-config": "^0.1.2",
4444
"@rollup/pluginutils": "^5.1.3",

packages/tailwindcss-patch/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# tailwindcss-patch
22

3-
\[[中文(zh-cn)](./README-cn.md)\]
4-
53
get tailwindcss context at runtime ! extract all classes into file!
64

75
- [tailwindcss-patch](#tailwindcss-patch)
6+
- [Docs](#docs)
87
- [Setup](#setup)
98
- [Usage](#usage)
109
- [Cli](#cli)
@@ -16,6 +15,10 @@ get tailwindcss context at runtime ! extract all classes into file!
1615

1716
> Nodejs version should >= `16.6.0`
1817
18+
## Docs
19+
20+
[mangle.icebreaker.top](https://mangle.icebreaker.top)
21+
1922
## Setup
2023

2124
1. Install package

packages/unplugin-tailwindcss-mangle/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ It is recommended to read the documentation of [tailwindcss-patch](https://githu
77
> Now Support `vite` and `webpack`
88
99
- [unplugin-tailwindcss-mangle](#unplugin-tailwindcss-mangle)
10+
- [Docs](#docs)
1011
- [Features](#features)
1112
- [Usage](#usage)
1213
- [1. Install Package](#1-install-package)
@@ -21,6 +22,10 @@ It is recommended to read the documentation of [tailwindcss-patch](https://githu
2122
- [Notice](#notice)
2223
- [Migration form v1 to v2](#migration-form-v1-to-v2)
2324

25+
## Docs
26+
27+
[mangle.icebreaker.top](https://mangle.icebreaker.top)
28+
2429
## Features
2530

2631
```html

pnpm-lock.yaml

Lines changed: 303 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/pages/_meta.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

website/pages/en/_meta.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
'index': 'Homepage',
3+
'---': {
4+
type: 'separator',
5+
},
6+
'patch': '1.Patch',
7+
'mangle': '2.Mangle',
8+
'config': '3.Config',
9+
'recommend': {
10+
display: 'hidden',
11+
},
12+
}

website/pages/en/config.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TODO

website/pages/en/index.mdx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
2+
import { Callout } from 'nextra/components'
3+
14
# Welcome to Tailwindcss-mangle
2-
3-
# Step
45

5-
1. [Patch](./patch)
6-
2. [Mangle](./mangle)
6+
## What is tailwindcss-mangle?
7+
8+
This is a project for compressing and obfuscating the class names generated by `tailwindcss`.
9+
10+
The purpose of creating this library is to prevent easy copying and plagiarism of pages developed using `tailwindcss`.
11+
12+
By using `tailwindcss-mangle`, it adds a bit of "cost" for potential copycats.
13+
14+
## How to use?
15+
16+
Currently, the usage process is mainly divided into 2 steps:
17+
18+
1. `Patch`
19+
2. `Mangle`
20+
21+
## Patch
22+
23+
This step is used to apply a patch to `tailwindcss` that exposes the context, so it can extract the `Token` it uses internally.
24+
25+
Eventually, it exports these as a `Json` file.
26+
27+
## Mangle
28+
29+
This step reads the `Json` exported from `Patch` and escapes all the string literals and template strings corresponding to the `Token`.

website/pages/en/mangle.mdx

Lines changed: 38 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,49 @@
1-
# unplugin-tailwindcss-mangle
1+
import { Callout } from 'nextra/components'
22

3-
mangle tailwindcss utilities plugin
3+
# 2. Mangle
44

5-
It is recommended to read the documentation of [tailwindcss-patch](https://github.com/sonofmagic/tailwindcss-mangle/tree/main/packages/tailwindcss-patch) first, `unplugin-tailwindcss-mangle` depends on this tool.
6-
7-
> Now Support `vite` and `webpack`
8-
9-
- [unplugin-tailwindcss-mangle](#unplugin-tailwindcss-mangle)
10-
- [Features](#features)
11-
- [Usage](#usage)
12-
- [1. Install Package](#1-install-package)
13-
- [2. Run install script](#2-run-install-script)
14-
- [3. add `prepare` script in your `package.json`](#3-add-prepare-script-in-your-packagejson)
15-
- [4. Run extract command](#4-run-extract-command)
16-
- [5. Register this plugin](#5-register-this-plugin)
17-
- [vite](#vite)
18-
- [webpack](#webpack)
19-
- [Nuxt 3](#nuxt-3)
20-
- [Options](#options)
21-
- [Notice](#notice)
22-
- [Migration form v1 to v2](#migration-form-v1-to-v2)
23-
24-
## Features
5+
## Feature Overview
256

267
```html
27-
<!-- before -->
8+
<!-- Before -->
289
<div class="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex"></div>
29-
<!-- after -->
10+
<!-- After -->
3011
<div class="tw-g tw-h tw-i tw-d tw-e tw-j tw-k tw-l"></div>
3112
```
3213

3314
## Usage
3415

35-
### 1. Install Package
16+
### 1. Install the package
3617

3718
```sh
38-
<npm|yarn|pnpm> i -D unplugin-tailwindcss-mangle tailwindcss-patch
19+
npm i -D unplugin-tailwindcss-mangle tailwindcss-patch
3920
```
4021

41-
### 2. Run install script
22+
### 2. Run the installation script
4223

4324
```sh
4425
npx tw-patch install
4526
```
4627

47-
### 3. add `prepare` script in your `package.json`
28+
### 3. Add the `prepare` script in `package.json`
4829

4930
```json
5031
"scripts": {
5132
"prepare": "tw-patch install"
5233
},
5334
```
5435

55-
### 4. Run extract command
36+
### 4. Run the extraction command
5637

57-
cd to the same directory as `package.json` and `tailwind.config.js`, then run:
38+
Navigate to the same directory as your `package.json` and `tailwind.config.js`, then run:
5839

5940
```sh
6041
npx tw-patch extract
6142
```
6243

6344
> See more options in [tailwindcss-patch](https://github.com/sonofmagic/tailwindcss-mangle/tree/main/packages/tailwindcss-patch)
6445
65-
Then there will generate a json file: `.tw-patch/tw-class-list.json`
46+
This will generate a JSON file: `.tw-patch/tw-class-list.json`
6647

6748
### 5. Register this plugin
6849

@@ -71,34 +52,34 @@ Then there will generate a json file: `.tw-patch/tw-class-list.json`
7152
```js
7253
import vue from '@vitejs/plugin-vue'
7354
import utwm from 'unplugin-tailwindcss-mangle/vite'
74-
// for example: vue vite project
55+
// For example: vue vite project
7556
import { defineConfig } from 'vite'
7657
// https://vitejs.dev/config/
7758
export default defineConfig({
7859
plugins: [vue(), utwm()]
7960
})
8061
```
8162

82-
then run script:
63+
Then run the script:
8364

8465
```sh
85-
# generate bundle
66+
# Build the package
8667
yarn build
87-
# preview
68+
# Preview
8869
yarn preview
8970
```
9071

91-
You will see all class was renamed to `tw-*`
72+
You will see that all class names are renamed to `tw-*`
9273

9374
#### webpack
9475

9576
```js
9677
// esm
9778
import { webpackPlugin as utwm } from 'unplugin-tailwindcss-mangle'
98-
// or cjs
79+
// Or cjs
9980
const utwm = require('unplugin-tailwindcss-mangle/webpack')
100-
// use this webpack plugin
101-
// for example next.config.js
81+
// Use this webpack plugin
82+
// For example in next.config.js
10283
const { defineConfig } = require('@vue/cli-service')
10384
// vue.config.js
10485
module.exports = defineConfig({
@@ -109,60 +90,37 @@ module.exports = defineConfig({
10990
}
11091
}
11192
})
112-
11393
```
11494

115-
#### Nuxt 3
95+
## Notes
11696

117-
```ts
118-
import nuxtPlugin from 'unplugin-tailwindcss-mangle/nuxt'
119-
export default defineNuxtConfig({
120-
// ...
121-
// https://github.com/nuxt/nuxt/issues/20428
122-
// you must set this option to false to enable vite extract css
123-
experimental: {
124-
inlineSSRStyles: false
125-
},
126-
modules: [
127-
[
128-
nuxtPlugin,
129-
{
130-
// options
131-
}
132-
]
133-
]
134-
})
135-
```
97+
This plugin only transforms utility class names that contain `-` or `:`, such as `w-32`, `before:h-[300px]`, `after:dark:via-[#0141ff]/40`. Some class names like `flex`, `relative` will not be transformed.
13698

137-
## Options
99+
The plugin **traverses** all `html class` attributes and `js` string literals to find the utility classes generated by `tailwindcss`.
138100

139-
[types.ts](src/types.ts)
101+
Transforming string literals like the following in `js` is dangerous:
140102

141-
## Notice
103+
```js
104+
const innerHTML = 'i\'m flex and relative and grid'
105+
document.body.innerHTML = innerHTML
106+
```
142107

143-
By default, only the build will take effect. Due to some restrictions, it cannot take effect in the development mode.
108+
Thus, only strings containing `-` or `:` will be transformed.
144109

145-
This plugin only transform those classes which name contain `-` or `:`, like `w-32`, `before:h-[300px]`,`after:dark:via-[#0141ff]/40`. some classes like `flex`,`relative` will not be mangled.
110+
Additionally, the plugin provides the `twIgnore` option, which allows some strings to be skipped during the `Mangle`.
146111

147-
because plugin will **traverse** all `html class attr` and `js StringLiteral` to find `utilities` generated by `tailwindcss`.
112+
For example:
148113

149-
it's dangerous to mangle some `js StringLiteral` like:
114+
### Input
150115

151116
```js
152-
const innerHTML = 'i\'m flex and relative and grid'
153-
document.body.innerHTML = innerHTML
117+
const twIgnore = String.raw;
118+
const className = `${twIgnore`gap-y-4`} bg-zinc-800/30`;
154119
```
155120

156-
so only strings with `-` or `:` will be transformed.
157-
158-
## Migration form v1 to v2
121+
### Output
159122

160-
```diff
161-
// vite
162-
- import { vitePlugin } from 'unplugin-tailwindcss-mangle'
163-
+ import utwm from 'unplugin-tailwindcss-mangle/vite'
164-
165-
// webpack
166-
- import { webpackPlugin } from 'unplugin-tailwindcss-mangle'
167-
+ import utwm from 'unplugin-tailwindcss-mangle/webpack'
123+
```js
124+
const twIgnore = String.raw;
125+
const className = `${twIgnore`gap-y-4`} tw-a`;
168126
```

0 commit comments

Comments
 (0)