sveltejs / svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
MIT License
1.73k stars 147 forks source link

Investigate parsel and css-selector-parser for new globalfication. #633

Open gregschmit opened 1 month ago

gregschmit commented 1 month ago

This is a draft of refactoring the globalifySelector to use a CSS parser rather than a regex to hopefully allow major libraries like Tailwind and DaisyUI to work better with Svelte.

I put more details in the globalfy/README.md however I'll summarize here:

My main goal for opening this PR in draft is to get feedback on if there is any likelihood this could get merged and, since it's a fairly significant change, if the maintainers of this project want to push me in a particular direction or otherwise provide feedback.

Thanks

This is also related to and would probably fix #501. Though if the maintainers are OK with it I would prefer the quick and dirty https://github.com/sveltejs/svelte-preprocess/pull/632 get merged to fix that since it's ready to go and simpler. It at least gets Tailwind to work property, however DaisyUI still doesn't work, and that's what this PR is all about.

Conduitry commented 1 month ago

I don't think we want to introduce a new CSS parsing dependency (for all users) just for <style global>.

I'm not a fan of this feature. I'd be in favor of deprecating and eventually removing this behavior altogether. It was added ages ago - while svelte-preprocess was still a personal project of kaisermann's rather than an official project under the sveltejs org - and before other tooling was able to support importing CSS files from JS to inject them (unscoped) into the application. Furthermore, in Svelte 5 you'll also be able to wrap everything in :global this way: <style> :global { div { color: red; } } </style>

If limitations in <style global> can push people to using one of the other solutions, I'd see that as more of a benefit, honestly - and I do want to more overtly push people in those other directions eventually anyway.