1.0.0 • Published 8 months ago

lit-tailwind-poc-2 v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

Get started

To run the project: 1) npm install (only the first time) 2) npm start to run the server 3) to develop the library, run npm build and copy the static assets where you need them.

You may clone this repo and start developing your components by looking at the test.component as reference.

As an alternative, and if you like to have control over every piece, do the following:

1) copy the files in the shared folder:

  • tailwind.element.ts extends LitElement by adding the tailwind support
  • tailwind.global.css includes tha Tailwind base classes into each component
  • globals.d.ts is used to avoid TypeScript errors whe nimporting CSS/Scss files in typescript files (thanks @emaant96) 2) copy the package.json or the devDependencies inside into your own package.json (there are no dependencies) 3) copy postcss.config.js, tailwind.config.js and tsconfig.js

That's all.

Show me the pieces

If you want to understand how it works, it's simple:

  • the package.json integrates these technolgies:
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"lit": "^2.4.0",
"tailwindcss": "^3.2.0",
"typescript": "^4.8.4",
"vite": "^3.1.8",
"sass": "^1.55.0"
  • vite does almost all the work automatically
  • to integrate tailwind, the most important file is in src/shared/tailwind.element.ts
import {LitElement, unsafeCSS} from "lit";

import style from "./tailwind.global.css";

const tailwindElement = unsafeCSS(style);

export const TailwindElement = (style) =>
    class extends LitElement {

        static styles = [tailwindElement, unsafeCSS(style)];
    
    };

It extends a LitElement class at runtime and adds the component tailwind classes.

The style variable comes from your component, where it is imported from an external CSS (or SCSS) file.

Then it is combined with the default tailwind classes.

If you add more components, the common parts are reused.

Who uses it?

We developed this starter kit to implement a web session player for our open source SaaS browserbot.

If you want to contribute or share soem thoughts, just get in touch with us.

Enjoy.