Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lit-dev-content): add lit-with-tailwind guide #1278

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

43081j
Copy link

@43081j 43081j commented Dec 10, 2023

This adds a guide for using tailwind (and similar libraries) with lit components.

For now, using the older import assertions proposal since esbuild doesn't yet support import attributes out of the box it seems.

for the author meta, i just dumped my twitter avatar in with the other images and updated the json. hopefully that works, i don't have many photos lying around 😂

@augustjk
Copy link
Member

augustjk commented Dec 11, 2023

@redfox-mx
Copy link

Hi! @43081j, @augustjk. Nice to meet you!

Today I just reviewed t39/import-attributes support and I noticed that the spec was updated and the previous 'with' keyword came back. So... I think maybe we need to wait for a little (with stability in mind) and see how the ecosystem moves.

PS: I was surfing and I find this PR 🤣, sorry for any inconvenience

@43081j
Copy link
Author

43081j commented Dec 11, 2023

I have mentioned that in the article

esbuild doesn't seem to support the latest standard out of the box, so the article still uses assert, but does mention with should be used when possible

I don't think we need to wait. It is pretty much settled now on import attributes (with)

@augustjk
Copy link
Member

I don't think we need to wait. It is pretty much settled now on import attributes (with)

Agreed. I think it's fine to publish now with the notes and update when we can.

Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! A few suggestions for typo and questions for my understanding of the solution.

It would also be nice to have a thumbnail to show up on https://pr1278-81e742c---lit-dev-5ftespv5na-uc.a.run.app/learn/

Normally I'd ask Andrew for his artistic talents but he's off on vacation til next year. Maybe it won't be hard to throw together something with the Lit and Tailwind logos. Time to bring out my MSPaint skills?

Comment on lines +38 to +42
- Use [import attributes](https://github.com/tc39/proposal-import-attributes)
to import those CSS files
- Use [esbuild](https://github.com/evanw/esbuild) to pull those CSS files
into the bundle or same output directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm not too familiar with features in this area and this is more for my understanding of what's going on.

Looking at the output from the example repo, esbuild produces this line in the bundle

import styles from "./hello-world-4K4DCJGM.css" assert { type: "css" };

esbuild is being used to bundle and move the css files into the outdir and is it then left up to the users to make this work on unsupported browsers? We probably need a loud caveat stating this only works in Chrome if that's the case. Can es-module-shims be used to make it work for other browser?

Might there be rollup plugins that work with the new correct import attribute syntax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... latest esbuild actually does support import attributes with the with keyword. https://github.com/evanw/esbuild/releases/tag/v0.19.7

evanw/esbuild#3384 (comment) Evan does say type: 'css' support will come to esbuild eventually but perhaps a plugin can be written for it in the mean time?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah pretty much, right now it just outputs the source as-is (i.e. your browser needs to support import assertions at least, ideally attributes too).

the esbuild blockage is because of no support for CSS. you're right though, we may be able to use a plugin, i'll have a dig around

it'd be nice to not have to use rollup, just because it consumes most of the build whereas esbuild focuses on only the bundling (as in we should also do the tailwind preprocessing in rollup, if we use rollup).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense. i don't disagree with the tool choice and i don't want to block or dictate too much as to what this article should say.

since this article being the first of its kind, i think it would be good to convey to the reader that this is meant as one way to solve this problem, with caveats like browser support, and mention alternatives (even without details) like using rollup plugins for all the steps. being published on lit.dev, people might consider this the only recommended way otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya, seeing how with is shipped in chrome now + TS 5.4 supporting it, can we switch to with?

@justinfagnani
Copy link
Contributor

Thanks for the article @43081j !!

Copy link
Member

@e111077 e111077 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I LOVE the image you have but there might be a potential legal issue:

https://tailwindcss.com/brand

Their brand guidance states:

You may not use the Tailwind name or logos in any way that could mistakenly imply any official connection with or endorsement of Tailwind Labs Inc.

I think inclusion of the logo like this can be construed as an endorsement. Maybe you can use the literal unicode as an alternative and standard arial or Manrope text. Or just Lit + Tailwind with Manrope font or standard arial

Comment on lines +38 to +42
- Use [import attributes](https://github.com/tc39/proposal-import-attributes)
to import those CSS files
- Use [esbuild](https://github.com/evanw/esbuild) to pull those CSS files
into the bundle or same output directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya, seeing how with is shipped in chrome now + TS 5.4 supporting it, can we switch to with?


An example repository very similar to this guide is available here:

https://github.com/43081j/tailwind-lit-example
Copy link
Member

@e111077 e111077 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do a link that's like:

[Source](https://github.com/43081j/tailwind-lit-example)
[Live demo](https://githubblitz.com/43081j/tailwind-lit-example)

All you would also need to do is have a start npm command that starts a server so that we can serve it like with WDS.

Here is an example with wds and a dev command:

https://stackblitz.com/edit/github-8tsp9c?file=src%2Fhello-world.ts

@43081j
Copy link
Author

43081j commented May 16, 2024

I'll try get the branch caught up and see if everything now works fine with import attributes

A designer friend of mine made the image. I'll ask her nicely and see if she can update 😅

I think it would make sense to just use text for the tailwind part and drop the logo

This adds a guide for using tailwind (and similar libraries) with lit
components.

For now, using the older import assertions proposal since esbuild
doesn't yet support import attributes out of the box it seems.
@43081j
Copy link
Author

43081j commented May 19, 2024

we're in a bit of a pickle with a stackblitz example 😬

it seems we can't use with until CSS modules are a thing. esbuild won't implement it, so it'll just throw a build error if you try use it unless you write a plugin for it.

i don't really want to get everyone to duplicate an esbuild plugin for something that should really work out of the box

but i can't put it back to asserts because browsers won't support that 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants