import postcss from "postcss"; import { transform } from "lightningcss"; const LEGACY_CHROME = 100 << 16; /** * Keep Vite's PostCSS pipeline (required by Tailwind 4), then compile the * resulting CSS to Chrome 100-compatible syntax for both dev and production. */ export default function lightningCssLegacyChrome() { return { postcssPlugin: "postcss-lightningcss-legacy-chrome", OnceExit(root, { result }) { const filename = root.source?.input.file ?? result.opts.from ?? "style.css"; const output = transform({ filename, code: Buffer.from(root.toString()), targets: { chrome: LEGACY_CHROME }, minify: false, }); const compiled = postcss.parse(output.code.toString(), { from: filename }); root.removeAll(); root.append(compiled.nodes); for (const warning of output.warnings) { result.warn(warning.message, { plugin: "lightningcss" }); } }, }; } lightningCssLegacyChrome.postcss = true;