unplugin-tailwindcss-mangle 0.0.1 → 0.0.2

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,96 +1,96 @@
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.
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 contain `-` 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.
package/dist/esbuild.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: (options?: import("./types").Options | undefined) => import("unplugin").EsbuildPlugin;
1
+ declare const _default: (options?: import("./types").Options | undefined) => import("esbuild").Plugin;
2
2
  export default _default;
package/dist/index.js CHANGED
@@ -386,7 +386,7 @@ function cssHandler(rawSource, options) {
386
386
  }
387
387
 
388
388
  const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
389
- const mangleClass = (className) => {
389
+ const isMangleClass = (className) => {
390
390
  return /[-:]/.test(className);
391
391
  };
392
392
  let classSet;
@@ -394,7 +394,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
394
394
  function getCachedClassSet() {
395
395
  const set = tailwindcssPatch.getClassCacheSet();
396
396
  set.forEach((c) => {
397
- if (!mangleClass(c)) {
397
+ if (!isMangleClass(c)) {
398
398
  set.delete(c);
399
399
  }
400
400
  });
@@ -408,6 +408,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
408
408
  generateBundle: {
409
409
  handler(options, bundle, isWrite) {
410
410
  const runtimeSet = getCachedClassSet();
411
+ if (!runtimeSet.size) {
412
+ return;
413
+ }
411
414
  const groupedEntries = getGroupedEntries(Object.entries(bundle));
412
415
  if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
413
416
  for (let i = 0; i < groupedEntries.html.length; i++) {
@@ -448,6 +451,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
448
451
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
449
452
  }, (assets) => {
450
453
  const runtimeSet = getCachedClassSet();
454
+ if (!runtimeSet.size) {
455
+ return;
456
+ }
451
457
  const groupedEntries = getGroupedEntries(Object.entries(assets));
452
458
  if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
453
459
  for (let i = 0; i < groupedEntries.html.length; i++) {
package/dist/index.mjs CHANGED
@@ -377,7 +377,7 @@ function cssHandler(rawSource, options) {
377
377
  }
378
378
 
379
379
  const unplugin = createUnplugin((options = {}, meta) => {
380
- const mangleClass = (className) => {
380
+ const isMangleClass = (className) => {
381
381
  return /[-:]/.test(className);
382
382
  };
383
383
  let classSet;
@@ -385,7 +385,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
385
385
  function getCachedClassSet() {
386
386
  const set = getClassCacheSet();
387
387
  set.forEach((c) => {
388
- if (!mangleClass(c)) {
388
+ if (!isMangleClass(c)) {
389
389
  set.delete(c);
390
390
  }
391
391
  });
@@ -399,6 +399,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
399
399
  generateBundle: {
400
400
  handler(options, bundle, isWrite) {
401
401
  const runtimeSet = getCachedClassSet();
402
+ if (!runtimeSet.size) {
403
+ return;
404
+ }
402
405
  const groupedEntries = getGroupedEntries(Object.entries(bundle));
403
406
  if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
404
407
  for (let i = 0; i < groupedEntries.html.length; i++) {
@@ -439,6 +442,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
439
442
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
440
443
  }, (assets) => {
441
444
  const runtimeSet = getCachedClassSet();
445
+ if (!runtimeSet.size) {
446
+ return;
447
+ }
442
448
  const groupedEntries = getGroupedEntries(Object.entries(assets));
443
449
  if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
444
450
  for (let i = 0; i < groupedEntries.html.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-tailwindcss-mangle",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "mangle tailwindcss utilities class",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -64,7 +64,7 @@
64
64
  "postcss-selector-parser": "^6.0.11",
65
65
  "semver": "^7.5.0",
66
66
  "unplugin": "^1.3.1",
67
- "tailwindcss-patch": "1.0.0"
67
+ "tailwindcss-patch": "1.0.1"
68
68
  },
69
69
  "publishConfig": {
70
70
  "access": "public",