MCPcopy Create free account
hub / github.com/rolldown/tsdown / transformWithLightningCSS

Function transformWithLightningCSS

packages/css/src/lightningcss.ts:45–81  ·  view source on GitHub ↗
(
  code: string,
  filename: string,
  options: TransformCssOptions,
)

Source from the content-addressed store, hash-verified

43}
44
45export async function transformWithLightningCSS(
46 code: string,
47 filename: string,
48 options: TransformCssOptions,
49): Promise<TransformCssResult> {
50 const targets =
51 options.lightningcss?.targets ??
52 (options.target ? esbuildTargetToLightningCSS(options.target) : undefined)
53 if (
54 !targets &&
55 !options.lightningcss &&
56 !options.minify &&
57 !options.cssModules
58 ) {
59 return { code }
60 }
61
62 const { transform } = await import('lightningcss')
63 const result = transform({
64 filename,
65 code: encoder.encode(code),
66 ...options.lightningcss,
67 targets,
68 minify: options.minify,
69 cssModules: options.cssModules,
70 sourceMap: options.sourceMap,
71 inputSourceMap: options.inputSourceMap,
72 })
73
74 return {
75 code: decoder.decode(result.code),
76 map: result.map ? decoder.decode(result.map) : undefined,
77 modules: result.exports
78 ? extractLightningCssModuleExports(result.exports)
79 : undefined,
80 }
81}
82
83export async function bundleWithLightningCSS(
84 filename: string,

Callers 4

finalizeCssFunction · 0.90
processWithLightningCSSFunction · 0.90
processWithPostCSSFunction · 0.90

Calls 3

transformFunction · 0.85

Tested by

no test coverage detected