()
| 10 | * browserslistToTargets. |
| 11 | */ |
| 12 | export function pluginLightningcssWasm(): PandaPlugin { |
| 13 | return { |
| 14 | name: 'playground-lightningcss-wasm', |
| 15 | hooks: { |
| 16 | 'css:optimize': ({ css, minify }) => { |
| 17 | try { |
| 18 | const { Features, transform } = require('lightningcss-wasm') |
| 19 | |
| 20 | const encoder = new TextEncoder() |
| 21 | const decoder = new TextDecoder() |
| 22 | |
| 23 | const result = transform({ |
| 24 | code: encoder.encode(css), |
| 25 | minify: minify ?? false, |
| 26 | sourceMap: false, |
| 27 | filename: 'styles.css', |
| 28 | include: Features.Nesting | Features.MediaRangeSyntax, |
| 29 | errorRecovery: true, |
| 30 | }) |
| 31 | |
| 32 | return decoder.decode(result.code) |
| 33 | } catch { |
| 34 | // Fall through to PostCSS if wasm isn't available |
| 35 | return undefined |
| 36 | } |
| 37 | }, |
| 38 | }, |
| 39 | } |
| 40 | } |
no test coverage detected