Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit c035d01

Browse files
committed
feat(compiler): add support for inline styles preprocessing
1 parent d5e5fc3 commit c035d01

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

compiler/mod.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,28 @@ export async function transform(url: string, code: string, options: TransformOpt
125125
}, '')
126126
.replace(/\:\s*%%aleph-inline-style-expr-(\d+)%%/g, (_, id) => `: var(--aleph-inline-style-expr-${id})`)
127127
.replace(/%%aleph-inline-style-expr-(\d+)%%/g, (_, id) => `/*%%aleph-inline-style-expr-${id}%%*/`)
128-
if (style.type !== 'css' && loaders !== undefined) {
128+
if (loaders !== undefined) {
129+
if (style.type !== 'css') {
130+
for (const loader of loaders) {
131+
if (loader.test.test(`.${style.type}`)) {
132+
const { code, type } = await loader.transform({ url: key, content: (new TextEncoder).encode(tpl) })
133+
if (type === 'css') {
134+
tpl = code
135+
break
136+
}
137+
}
138+
}
139+
}
129140
for (const loader of loaders) {
130-
if (loader.test.test(`.${style.type}`)) {
131-
const { code, type } = await loader.transform({ url, content: (new TextEncoder).encode(tpl) })
141+
if (loader.test.test('.css')) {
142+
const { code, type } = await loader.transform({ url: key, content: (new TextEncoder).encode(tpl) })
132143
if (type === 'css') {
133144
tpl = code
134145
break
135146
}
136147
}
137148
}
138149
}
139-
// todo: postcss and minify
140150
tpl = tpl.replace(
141151
/\: var\(--aleph-inline-style-expr-(\d+)\)/g,
142152
(_, id) => ': ${' + style.exprs[parseInt(id)] + '}'

0 commit comments

Comments
 (0)