Replies: 6 comments 4 replies
-
Hi all, I've described more cases which would be nice to support 43081j/postcss-lit#47. According to the lit docs, they are all possible and, actually, on my project |
Beta Was this translation helpful? Give feedback.
-
I would like to use external .css, but after upgrading npm packages had issues and gave up. Upgraded to rollup 3 and installed rollup-plugin-import-css, but had csstag browser errors after copying the website to the web server. |
Beta Was this translation helpful? Give feedback.
-
I personally use external css via @bennypowers’s lit-css and happy with it. I will also definitely try CSS Module Scripts once its arrived to browsers. I would like to see built-in support (maybe with a polyfilll for CSS modules) for using external files. |
Beta Was this translation helpful? Give feedback.
-
FWIW and IMO it's a great idea to document the "interpolate in your ts sources and pile ast-aware tools on top" approach, but I think it would be a liability to support that by moving such tooling into the monorepo. This especially as the import assertions proposal has pivoted from |
Beta Was this translation helpful? Give feedback.
-
honestly, we do a lot with a custom directive along the lines of |
Beta Was this translation helpful? Give feedback.
-
Hi! Recently I have noticed one of the biggest problems with how "normal" css template tags work in lit. Beyond how you can import your styles, css tooling nowadays does a lot more. Transform your css dialects, add browser-specific prefixes, generate on-demand css classes, or create hashed identifiers for your shared styles. And usually, these features are part of css ecosystem through bundlers plugins, so you don't need to reinvent the wheel! Probably our focus should need to be on how to integrate these cool plugins into a lit-specific context. I start to look at the work of @bennypowers and @43081j with lit-css monorepo and lit-postcss, and It is cool!!. I dream about some holistic approach with both initiatives lit-css only needs to take care of how to transform code from resulting css post-processed files into lit tagged templates (with some ast code manipulations, just like postcss-lit does). It can be more powerful and easier to integrate with other tools. I don't know, maybe I am so enthusiastic or innocent, but we can build great things together. PS: Of course, I write another plugin for vite (maybe you must try the alpha tag and not the latest) vite-plugin-lit-css |
Beta Was this translation helpful? Give feedback.
-
i figured a discussion might be the best place to track this stuff since it can easily get lost on discord.
CSS in lit components basically has two ways of working right now:
static styles
, adopted sheets, etc)in the recent eng catch ups we decided to lean more towards people using external CSS if they want to make use of css tooling.
External CSS
In an ideal world, we would have import assertions and CSS modules such that this works:
For now, you can still achieve this without import assertions by using a bundler.
Pros
Cons
Existing solutions
rollup-plugin-import-css
exists to allow you to import CSS in your JS files via rollup (also supports import assertions).Various other equivalent solutions exist for webpack, esbuild and so on too.
Embedded CSS
Using lit styles as normal:
In order to use any tooling with this, you would need something which understands template literals and expression interpolation into them.
Pros
Cons
Existing solutions
postcss-lit
exists as a custom syntax to tell postcss how to interpret embedded CSS. Most CSS tooling depends on postcss so this allows users to use tailwind, stylelint, etc already.However, it needs a bit of a refactor at some point and I am the sole maintainer so it is taking a long time.
I won't go into it too much but it all comes down to handling interpolations. There are two solutions, both are fairly complex and both have their downsides. There isn't really a "perfect" solution.
Examples
Some examples i've seen of why people would choose to embed css over making it external. Most are to do with interpolations.
From a related GH issue:
From another GH comment:
I think @bennypowers also has something along these lines at redhat (for now).
You get the idea. People are using interpolations to essentially create their design system CSS at run-time via computations.
Of course we could argue people should do that at build time, and it would be more efficient (for the user, bundle size, etc).
However, we should assume the worst: that these people don't have the time/budget to refactor their design systems so are likely to stick with what they have.
Wrap up
Personally i feel like we can't push one way or the other. We need to at least have basic support or documentation (or both) for both solutions/directions.
For external stylesheets, i suggest we document "integrations" somewhere on lit.dev. For example, a brief page for:
For embedded stylesheets, I already have the majority of the postcss syntax we need. There's a very large bump in the road im slowly climbing up. If i had any help getting over that, I feel like it'd be a fairly stable solution we'd barely have to touch ever again.
I'd also be happy to move postcss-lit into the monorepo if thats a sensible idea at some point too. Keep in mind though, it has two parts:
Both are packages i maintain.
cc @kevinpschaaf @justinfagnani
Beta Was this translation helpful? Give feedback.
All reactions