Skip to content

Commit 8841807

Browse files
committed
perf: lazy import lightningcss
1 parent b1d2c4a commit 8841807

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/core/transform.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Buffer } from 'node:buffer'
22
import { readFile } from 'node:fs/promises'
3-
import { transform } from 'lightningcss'
43
import type { Options } from './options'
54

65
const postfixRE = /[#?].*$/s
76
function cleanUrl(url: string): string {
87
return url.replace(postfixRE, '')
98
}
109

11-
export function transformCss(
10+
export async function transformCss(
1211
id: string,
1312
code: string,
1413
options: Options['options'],
15-
): { code: string; map?: string } {
14+
): Promise<{ code: string; map?: string }> {
1615
const filename = cleanUrl(id)
16+
const { transform } = await import('lightningcss')
1717
const res = transform({
1818
...options,
1919
filename,
@@ -32,6 +32,7 @@ export async function transformCssModule(
3232
const actualId = id.replace(/\?css_module$/, '')
3333
const code = await readFile(actualId, 'utf-8')
3434
const filename = cleanUrl(actualId)
35+
const { transform } = await import('lightningcss')
3536
const res = transform({
3637
cssModules: true,
3738
...options,

0 commit comments

Comments
 (0)