-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
should prob open a discussion on the lightningcss side to figure out a better way of doing this, but this works for now
- Loading branch information
Showing
5 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { transform } from "lightningcss"; | ||
import { composePlugins, spacing, screen } from "."; | ||
|
||
const a = { | ||
filename: 'test.css', | ||
minify: true, | ||
code: new TextEncoder().encode('.foo {size: 0.25tw; @screen lg {size: 1tw; color: red;}}'), | ||
...composePlugins([spacing, screen]), | ||
} | ||
|
||
let { code, map } = transform(a); | ||
console.log(a) | ||
|
||
console.log(code.toString()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { composeVisitors, type CustomAtRules, type Visitor } from 'lightningcss'; | ||
|
||
export type Plugin<C extends CustomAtRules> = { | ||
visitor: Visitor<C>, | ||
customAtRules?: C | ||
} | ||
|
||
export function composePlugins<C extends CustomAtRules>(plugins: (Plugin<C> | Visitor<C>)[]) { | ||
let customAtRules: CustomAtRules = {}; | ||
let visitors: Visitor<CustomAtRules>[] = []; | ||
|
||
plugins.forEach(p => { | ||
if ('visitor' in p) { | ||
visitors.push(p.visitor) | ||
if (p.customAtRules) { Object.assign(customAtRules, p.customAtRules) } | ||
} else { | ||
visitors.push(p) | ||
} | ||
}); | ||
|
||
return { | ||
customAtRules, visitor: composeVisitors(visitors) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters