Skip to content

Commit d3ebc06

Browse files
committed
chore: use splitCode for get defaultExtractor
1 parent 6895d13 commit d3ebc06

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

packages/unplugin-tailwindcss-mangle/rollup.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export default createRollupConfig({
1313
{
1414
dir: 'dist',
1515
format: 'cjs',
16+
exports: 'auto',
17+
interop: 'auto',
1618
// entryFileNames: '[name].cjs',
1719
// chunkFileNames: '[name]-[hash].cjs',
1820
sourcemap: isDev,

packages/unplugin-tailwindcss-mangle/src/handlers/js.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { parse, traverse, generate } from '../lib/babel'
33
import type { Node } from '@babel/types'
44
import type { TraverseOptions, IJsHandlerOptions } from '../types'
55
import { escapeStringRegexp } from '../utils'
6+
import { splitCode } from './split'
67

78
export function jsHandler(rawSource: string, options: IJsHandlerOptions) {
89
const ast = parse(rawSource)
@@ -13,7 +14,7 @@ export function jsHandler(rawSource: string, options: IJsHandlerOptions) {
1314
StringLiteral: {
1415
enter(p) {
1516
const n = p.node
16-
const arr = n.value.split(/\s/).filter((x) => x)
17+
const arr = splitCode(n.value) // .split(/\s/).filter((x) => x)
1718
let rawStr = n.value
1819
for (let i = 0; i < arr.length; i++) {
1920
const v = arr[i]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/
2+
3+
export function isValidSelector(selector = ''): selector is string {
4+
return validateFilterRE.test(selector)
5+
}
6+
7+
export const splitCode = (code: string) => [...new Set(code.split(/\\?[\s'"`;={}]+/g))].filter(isValidSelector)

packages/unplugin-tailwindcss-mangle/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { getGroupedEntries } from './utils'
88
import { OutputAsset, OutputChunk } from 'rollup'
99
import ClassGenerator from './classGenerator'
1010
import { jsHandler } from './handlers/js'
11-
const unplugin = createUnplugin((options: Options = {}, meta) => {
11+
12+
const preserveClass = ['filter']
13+
const unplugin = createUnplugin((options: Options | undefined = {}, meta) => {
1214
let classSet: Set<string>
1315
let cached: boolean
1416
const clsGen = new ClassGenerator()
@@ -17,6 +19,9 @@ const unplugin = createUnplugin((options: Options = {}, meta) => {
1719
return classSet
1820
}
1921
const set = getClassCacheSet()
22+
preserveClass.forEach((c) => {
23+
set.delete(c)
24+
})
2025
classSet = set
2126
cached = true
2227
return classSet

packages/unplugin-tailwindcss-mangle/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"outDir": "dist",
55
"declarationDir": "dist",
6-
"module": "CommonJS",
76
"baseUrl": ".",
87
"paths": {
98
"@/*": [

0 commit comments

Comments
 (0)