mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Tailwind v4 projects typically include `@import "tailwindcss";` in their CSS entry and often `@import` third-party CSS plugins like `tw-animate-css`. Both cases were broken: 1. esbuild tried to resolve `tailwindcss` through the ESM CDN as JS, producing 'Cannot import <...> into a CSS file'. The existing CSS-importer guard used `new URL(args.importer)` to detect CSS importers, but esbuild passes fs-namespace importers as plain paths (e.g. `/projects/foo/src/index.css`) which don't parse as URLs, so the guard never fired. 2. `@tailwindcss/browser@4` only resolves a hardcoded set of `@import` specifiers (`tailwindcss`, `tailwindcss/preflight`, `tailwindcss/theme`, `tailwindcss/utilities`) and throws 'The browser build does not support @import for <x>' for everything else, so plugin packages couldn't be preserved as external either. Detect CSS importers with a plain string match and split behavior: `tailwindcss` and its subpaths stay external so the v4 runtime can handle them, while other bare CSS imports fall through to the normal esm.sh resolution path. esm.sh redirects CSS-only packages to their `.css` entry and `onLoad` picks `loader: "css"` via the content-type mapping, so the dependency is bundled inline. The combined CSS then lands in the `<style type="text/tailwindcss">` block where the v4 runtime can process v4 directives (`@custom-variant`, `@theme`, etc.) from third-party plugins.