Skip to content

Commit bbaa8b3

Browse files
committed
refactor: vue, svelte, and lightningcss to plugin
1 parent 8d3b6f8 commit bbaa8b3

36 files changed

+4182
-3022
lines changed

.changeset/plugin-architecture.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@pandacss/plugin-vue': minor
3+
'@pandacss/plugin-svelte': minor
4+
'@pandacss/plugin-lightningcss': minor
5+
'@pandacss/core': minor
6+
'@pandacss/parser': minor
7+
'@pandacss/node': minor
8+
'@pandacss/config': minor
9+
'@pandacss/types': minor
10+
---
11+
12+
- Extract Vue, Svelte, and LightningCSS support into standalone plugins.
13+
- Fix double CSS optimization in PostCSS plugin.

packages/config/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export { getResolvedConfig } from './get-resolved-config'
66
export { loadConfig } from './load-config'
77
export { resolveConfig } from './resolve-config'
88
export { mergeConfigs } from './merge-config'
9+
export { mergeHooks } from './merge-hooks'
910
export { convertTsPathsToRegexes } from './ts-config-paths'
1011
export type { BundleConfigResult } from './types'

packages/config/src/merge-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PANDA_CONFIG_NAME, assign, mergeWith, mergeAndConcat, walkObject } from '@pandacss/shared'
22
import type { Config } from '@pandacss/types'
33
import { mergeHooks } from './merge-hooks'
4+
export { mergeHooks }
45
import { isValidToken } from './validation/utils'
56

67
type Extendable<T> = T & { extend?: T }

packages/config/src/merge-hooks.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ const reducers = {
126126

127127
return preset
128128
}),
129+
'css:optimize': createReducer<'css:optimize'>((fns) => (_args) => {
130+
const args = Object.assign({}, _args)
131+
const original = _args.css
132+
let css = args.css
133+
134+
for (const hookFn of fns) {
135+
const result = hookFn(Object.assign(args, { css, original }))
136+
if (result !== undefined) {
137+
css = result
138+
}
139+
}
140+
141+
return css
142+
}),
129143
}
130144

131145
const syncHooks: Array<keyof PandaHooks> = [
@@ -134,6 +148,7 @@ const syncHooks: Array<keyof PandaHooks> = [
134148
'parser:preprocess',
135149
'parser:after',
136150
'cssgen:done',
151+
'css:optimize',
137152
]
138153

139154
const callAllAsync =

packages/core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
"@pandacss/token-dictionary": "workspace:*",
4646
"@pandacss/types": "workspace:*",
4747
"browserslist": "4.28.1",
48-
"hookable": "5.5.3",
49-
"lightningcss": "1.31.1",
5048
"lodash.merge": "4.6.2",
5149
"outdent": "0.8.0",
5250
"postcss": "8.5.6",

packages/core/src/context.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ export class Context {
344344
hooks: this.hooks,
345345
isValidProperty: this.isValidProperty,
346346
browserslist: this.config.browserslist,
347-
lightningcss: this.config.lightningcss,
348347
polyfill: this.config.polyfill,
349348
cssVarRoot: this.config.cssVarRoot!,
350349
helpers: patternFns,

packages/core/src/optimize.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
import type { PandaHooks } from '@pandacss/types'
12
import postcss, { Root } from 'postcss'
23
import nested from 'postcss-nested'
34
import { optimizePostCss } from './plugins/optimize-postcss'
45
import prettify from './plugins/prettify'
56

67
interface OptimizeOptions {
78
minify?: boolean
8-
lightningcss?: boolean
99
browserslist?: string[]
10+
hooks?: Partial<PandaHooks>
1011
}
1112

1213
export function optimizeCss(code: string | Root, options: OptimizeOptions = {}) {
13-
const { lightningcss } = options
14+
const { hooks } = options
15+
const css = typeof code === 'string' ? code : code.toString()
1416

15-
if (lightningcss) {
16-
const light = require('./plugins/optimize-lightningcss') as typeof import('./plugins/optimize-lightningcss')
17-
return light.default(code, options)
17+
if (hooks?.['css:optimize']) {
18+
const result = hooks['css:optimize']({
19+
css,
20+
minify: options.minify,
21+
browserslist: options.browserslist,
22+
})
23+
if (result !== undefined) {
24+
return result
25+
}
1826
}
1927

2028
return optimizePostCss(code, options)

packages/core/src/stylesheet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export class Stylesheet {
129129
.join('\n'),
130130
{
131131
minify: false,
132-
lightningcss: this.context.lightningcss,
133132
browserslist: this.context.browserslist,
133+
hooks: this.context.hooks,
134134
},
135135
)
136136
}
@@ -152,8 +152,8 @@ export class Stylesheet {
152152

153153
return optimizeCss(css, {
154154
minify,
155-
lightningcss: this.context.lightningcss,
156155
browserslist: this.context.browserslist,
156+
hooks: this.context.hooks,
157157
})
158158
} catch (error) {
159159
if (error instanceof CssSyntaxError) {

packages/core/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export interface StylesheetContext
4242
layers: Layers
4343
helpers: PatternHelpers
4444
hash?: boolean
45-
lightningcss?: boolean
4645
browserslist?: string[]
4746
polyfill?: boolean
4847
cssVarRoot: string

packages/node/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"@pandacss/config": "workspace:*",
4242
"@pandacss/core": "workspace:*",
4343
"@pandacss/generator": "workspace:*",
44+
"@pandacss/plugin-lightningcss": "workspace:*",
45+
"@pandacss/plugin-svelte": "workspace:*",
46+
"@pandacss/plugin-vue": "workspace:*",
4447
"@pandacss/reporter": "workspace:*",
4548
"@pandacss/logger": "workspace:*",
4649
"@pandacss/parser": "workspace:*",

0 commit comments

Comments
 (0)