@@ -8,10 +8,10 @@ import ClassGenerator from './classGenerator'
8
8
import { htmlHandler } from './html'
9
9
import { jsHandler } from './js'
10
10
import { cssHandler } from './css'
11
- import type { } from 'webpack'
11
+ import type { } from 'webpack'
12
12
const unplugin = createUnplugin ( ( options : Options | undefined = { } , meta ) => {
13
- // const preserveClass = ['filter']
14
- const mangleClass = ( className : string ) => {
13
+
14
+ const isMangleClass = ( className : string ) => {
15
15
// ignore className like 'filter','container'
16
16
// it may be dangerous to mangle/rename all StringLiteral , so use /-/ test for only those with /-/ like:
17
17
// bg-[#123456] w-1 etc...
@@ -21,21 +21,16 @@ const unplugin = createUnplugin((options: Options | undefined = {}, meta) => {
21
21
// let cached: boolean
22
22
const classGenerator = new ClassGenerator ( )
23
23
function getCachedClassSet ( ) {
24
- // if (cached) {
25
- // return classSet
26
- // }
24
+
27
25
const set = getClassCacheSet ( )
28
26
set . forEach ( ( c ) => {
29
- if ( ! mangleClass ( c ) ) {
27
+ if ( ! isMangleClass ( c ) ) {
30
28
set . delete ( c )
31
- // console.log(c)
32
29
}
33
30
} )
34
- // preserveClass.forEach((c) => {
35
- // set.delete(c)
36
- // })
31
+
37
32
classSet = set
38
- // cached = true
33
+
39
34
return classSet
40
35
}
41
36
return {
@@ -45,6 +40,9 @@ const unplugin = createUnplugin((options: Options | undefined = {}, meta) => {
45
40
generateBundle : {
46
41
handler ( options , bundle , isWrite ) {
47
42
const runtimeSet = getCachedClassSet ( )
43
+ if ( ! runtimeSet . size ) {
44
+ return
45
+ }
48
46
const groupedEntries = getGroupedEntries ( Object . entries ( bundle ) )
49
47
50
48
if ( Array . isArray ( groupedEntries . html ) && groupedEntries . html . length ) {
@@ -91,6 +89,9 @@ const unplugin = createUnplugin((options: Options | undefined = {}, meta) => {
91
89
// const resolvePath = require.resolve('tailwindcss')
92
90
// console.log(resolvePath)
93
91
const runtimeSet = getCachedClassSet ( )
92
+ if ( ! runtimeSet . size ) {
93
+ return
94
+ }
94
95
const groupedEntries = getGroupedEntries ( Object . entries ( assets ) )
95
96
if ( Array . isArray ( groupedEntries . html ) && groupedEntries . html . length ) {
96
97
for ( let i = 0 ; i < groupedEntries . html . length ; i ++ ) {
0 commit comments