Skip to content

Commit 086494b

Browse files
committed
feat: support svelte
1 parent 79ea57d commit 086494b

File tree

17 files changed

+141
-194
lines changed

17 files changed

+141
-194
lines changed

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@
6060
"type": "node-terminal",
6161
"cwd": "${workspaceFolder}/apps/vite-vanilla"
6262
},
63+
{
64+
"command": "pnpm dev",
65+
"name": "[vite-lit] dev",
66+
"request": "launch",
67+
"type": "node-terminal",
68+
"cwd": "${workspaceFolder}/apps/vite-lit"
69+
},
70+
{
71+
"command": "pnpm build",
72+
"name": "[vite-lit] build",
73+
"request": "launch",
74+
"type": "node-terminal",
75+
"cwd": "${workspaceFolder}/apps/vite-lit"
76+
},
77+
{
78+
"command": "pnpm dev",
79+
"name": "[vite-svelte] dev",
80+
"request": "launch",
81+
"type": "node-terminal",
82+
"cwd": "${workspaceFolder}/apps/vite-svelte"
83+
},
84+
{
85+
"command": "pnpm build",
86+
"name": "[vite-svelte] build",
87+
"request": "launch",
88+
"type": "node-terminal",
89+
"cwd": "${workspaceFolder}/apps/vite-svelte"
90+
},
6391
{
6492
"command": "pnpm dev",
6593
"name": "[webpack5-vue3] dev",

apps/vite-react/vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
plugins: [
77
react(),
88
utwm({
9-
classMapOutput: true
10-
})
11-
]
9+
classMapOutput: true,
10+
}),
11+
],
1212
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@changesets/changelog-github": "^0.5.0",
2828
"@changesets/cli": "^2.27.5",
2929
"@icebreakers/eslint-config": "^0.3.9",
30+
"@rollup/pluginutils": "^5.1.0",
3031
"@tailwindcss-mangle/core": "workspace:*",
3132
"@tailwindcss-mangle/shared": "workspace:*",
3233
"@tsconfig/recommended": "^1.0.6",

packages/config/src/defaults.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import process from 'node:process'
22
import { defaultMangleClassFilter } from '@tailwindcss-mangle/shared'
3+
34
import type { MangleUserConfig, PatchUserConfig, UserConfig } from './types'
45

6+
const defaultPipelineInclude = ['**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}']
7+
8+
const defaultPipelineExclude = [/[\\/](node_modules|dist|\.temp|\.cache|\.vscode)[\\/]/]
9+
510
export function getDefaultPatchConfig(): PatchUserConfig {
611
return {
712
output: {
@@ -16,8 +21,8 @@ export function getDefaultPatchConfig(): PatchUserConfig {
1621
export function getDefaultMangleUserConfig(): MangleUserConfig {
1722
return {
1823
mangleClassFilter: defaultMangleClassFilter,
19-
include: ['**/*.{js,jsx,ts,tsx,svelte,vue}'],
20-
exclude: ['node_modules/**/*', '**/*.{css,scss,less,sass,postcss,html,htm}'],
24+
include: defaultPipelineInclude,
25+
exclude: defaultPipelineExclude,
2126
disabled: process.env.NODE_ENV === 'development',
2227
classListPath: '.tw-patch/tw-class-list.json',
2328
classMapOutput: {

packages/config/src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { IClassGeneratorOptions } from '@tailwindcss-mangle/shared'
2+
import type { FilterPattern } from '@rollup/pluginutils'
23

34
export interface ClassMapOutputOptions {
45
enable?: boolean
@@ -9,8 +10,8 @@ export interface ClassMapOutputOptions {
910
export interface MangleUserConfig {
1011
mangleClassFilter?: (className: string) => boolean
1112
classGenerator?: IClassGeneratorOptions
12-
exclude?: string[]
13-
include?: string[]
13+
exclude?: FilterPattern
14+
include?: FilterPattern
1415
classListPath?: string
1516
classMapOutput?: ClassMapOutputOptions
1617
disabled?: boolean

packages/config/test/__snapshots__/defaults.test.ts.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ exports[`defaults > getDefaultUserConfig 1`] = `
2222
},
2323
"disabled": false,
2424
"exclude": [
25-
"node_modules/**/*",
26-
"**/*.{css,scss,less,sass,postcss,html,htm}",
25+
/\\[\\\\\\\\/\\]\\(node_modules\\|dist\\|\\\\\\.temp\\|\\\\\\.cache\\|\\\\\\.vscode\\)\\[\\\\\\\\/\\]/,
2726
],
2827
"include": [
29-
"**/*.{js,jsx,ts,tsx,svelte,vue}",
28+
"**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}",
3029
],
3130
"mangleClassFilter": [Function],
3231
"preserveFunction": [],

packages/config/test/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ exports[`config > 2.mangle-options 1`] = `
1414
},
1515
"disabled": false,
1616
"exclude": [
17-
"node_modules/**/*",
18-
"**/*.{css,scss,less,sass,postcss,html,htm}",
17+
/\\[\\\\\\\\/\\]\\(node_modules\\|dist\\|\\\\\\.temp\\|\\\\\\.cache\\|\\\\\\.vscode\\)\\[\\\\\\\\/\\]/,
1918
],
2019
"include": [
21-
"**/*.{js,jsx,ts,tsx,svelte,vue}",
20+
"**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}",
2221
],
2322
"mangleClassFilter": [Function],
2423
"preserveFunction": [],

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"@babel/types": "^7.24.7",
5858
"@tailwindcss-mangle/config": "workspace:^",
5959
"@tailwindcss-mangle/shared": "workspace:^",
60-
"@vue/compiler-sfc": "^3.4.29",
6160
"fast-sort": "^3.4.0",
6261
"htmlparser2": "9.1.0",
6362
"magic-string": "^0.30.10",

packages/core/src/html/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { Parser } from 'htmlparser2'
22
import MagicString from 'magic-string'
33
import type { IHtmlHandlerOptions } from '../types'
44
import { makeRegex, splitCode } from '../shared'
5-
import { jsHandler } from '@/js'
65

76
export function htmlHandler(raw: string | MagicString, options: IHtmlHandlerOptions) {
8-
const { ctx, isVue } = options
7+
const { ctx } = options
98
const { replaceMap } = ctx
109
const ms: MagicString = typeof raw === 'string' ? new MagicString(raw) : raw
1110
const parser = new Parser({
@@ -22,14 +21,14 @@ export function htmlHandler(raw: string | MagicString, options: IHtmlHandlerOpti
2221
}
2322
ms.update(parser.startIndex + name.length + 2, parser.endIndex - 1, rawValue)
2423
}
25-
if (isVue) {
26-
if (name === ':class') {
27-
const { code } = jsHandler(value, {
28-
ctx,
29-
})
30-
ms.update(parser.startIndex + name.length + 2, parser.endIndex - 1, code)
31-
}
32-
}
24+
// if (isVue) {
25+
// if (name === ':class') {
26+
// const { code } = jsHandler(value, {
27+
// ctx,
28+
// })
29+
// ms.update(parser.startIndex + name.length + 2, parser.endIndex - 1, code)
30+
// }
31+
// }
3332
},
3433
})
3534
parser.write(ms.original)

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ export * from './ctx'
22
export * from './css'
33
export * from './html'
44
export * from './js'
5-
export * from './vue'
65
export { ClassGenerator } from './shared'
76
export * from './types'

0 commit comments

Comments
 (0)