( code: string, filename: string, options: TransformCssOptions, )
| 43 | } |
| 44 | |
| 45 | export 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 | |
| 83 | export async function bundleWithLightningCSS( |
| 84 | filename: string, |
no test coverage detected