Coder Social home page Coder Social logo

lit-css's Introduction

Am Yisrael Chai - עם ישראל חי

lit-CSS Plugins

Build plugins to import css files as JavaScript tagged-template literal objects.

The "Lit" stands for "Literal"

You can use it to import CSS for various libraries like lit-element, @microsoft/fast-element, or others.

Do I Need This?

No. These are optional packages whose sole purpose is to make it easier to write CSS-in-CSS. You can just as easily write your CSS in some 'styles.css.js' modules a la:

import { css } from 'lit';
export default css`:host { display: block; }`;

And this may actually be preferred.

Hopefully this package will become quickly obsolete when the CSS Modules Proposal (or something like it) is accepted and implemented.

In the mean time, enjoy importing your CSS into your component files.

lit-css's People

Contributors

bennypowers avatar christian24 avatar github-actions[bot] avatar peschee avatar sbolz avatar sledsworth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lit-css's Issues

CSS Modules / Import Assertions

Users should be able to opt-in to polyfilling css modules / import assertions, rather than getting the css-tagged-literal version

A later breaking version would switch it to opt-out (i.e., users would then have to opt-in to what is now current behaviour)

TS error due to missing `css` property in rollup plugin options

Given the following rollup config:

// @ts-check
import resolve from "@rollup/plugin-node-resolve"
import typescript from "@rollup/plugin-typescript"
import litCss from "rollup-plugin-lit-css"

export default {
  input: "src/index.ts",

  plugins: [
    // Resolve bare module specifiers to relative paths
    resolve({ extensions: [".mjs", ".js", ".json", ".ts"] }),

    // transform css files into Lit-compatible format
    litCss({ include: ["src/**/*.css"] }),

    // transform typescript
    typescript({
      include: ["src/index.ts", "src/**/*.ts", "globals.d.ts"],
    }),
  ],

  output: {
    dir: "lib",
    sourcemap: true,
  },
}

TS complains with the following error:

Argument of type '{ include: string[]; }' is not assignable to parameter of type 'LitCSSOptions'.
  Property 'css' is missing in type '{ include: string[]; }' but required in type 'LitCSSOptions'

url(..) calls

Hi, thank you so much for this library.

I am using this because I need auto-prefixing on my css, and I'm chaining postcss-loader before this. It's not working right now, and I don't really understand why.

Could we maybe document a known-good webpack config to do this?

Add support for esbuild 0.18.x

esbuild 0.18 has been released (see https://github.com/evanw/esbuild/blob/main/CHANGELOG.md) but npm refuses to update my dependencies:

npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @cedx/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/esbuild
npm WARN   dev esbuild@"^0.18.0" from the root project
npm WARN   1 more (esbuild-plugin-minify-html-literals)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer esbuild@"^0.16.17 || ^0.17.16" from [email protected]
npm WARN node_modules/esbuild-plugin-minify-html-literals
npm WARN   dev esbuild-plugin-minify-html-literals@"^1.0.4" from the root project

Can you check/fix this? Thank you in advance.

Use with create-react-app

Hi. I'm having issues using this with a create-react-app.
I'm using react-app-rewired and customize-cra to override the configs.

The config looks like this:

const { override, addWebpackModuleRule } = require('customize-cra');

module.exports = override(
  addWebpackModuleRule({
    test: /\.ccss$/,
    loader: 'lit-css-loader'
  })
);

But I get this error when trying to run the app:

Failed to compile.

./src/heimdall/components/text/styles.ccss
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: [path-to-my-app]/node_modules/lit-css-loader/lit-css-loader.js
require() of ES modules is not supported.
require() of [path-to-my-app]/node_modules/lit-css-loader/lit-css-loader.js from [path-to-my-app]/node_modules/loader-runner/lib/loadLoader.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename lit-css-loader.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from [path-to-my-app]/node_modules/lit-css-loader/package.json.

Maybe you can help?

Thanks a lot.

Angular and React examples

Hi. I got very excited when I learned about this plugin on Twitter, it's exactly what we need on project using lit elements.
However I'm having problems configuring this in an Angular (12+) app.

Could you maybe give some guidance or advice on how to get up and running using Angular?

I'm currently trying using @angular-builders/custom-webpack, but no luck yet.

Thanks a lot and thanks for you work on this.

Please provide a project template for vite

My project use vite so that I choose rollup-plugin-lit-css。
this is my vite.config.js

import { defineConfig } from "vite";
import litcss from "rollup-plugin-lit-css";

export default defineConfig({
  plugins: [
    litcss({
      include: "/src/components/**/*.css",
      uglify: true,
    }),
  ],
  build: {
    lib: {
      entry: "src/my-element.js",
      formats: ["es"],
    },
    rollupOptions: {
      external: /^lit/,
    },
  },
});

and this is my element code

import { LitElement, css, html } from "lit";
import style from "./index.css";

export class HelloWorld extends LitElement {
  constructor() {
    super();
  }
  render() {
    return html` <div>Hello World</div> `;
  }
  static styles = [style];
}
window.customElements.define("hello-world", HelloWorld);

but vite echo Default and named imports from CSS files are deprecated. Use the ?inline query instead. For example: import style from "./index.css?inline
so the import code transform

import style from "./index.css?inline";

but lit echo Failed to set the 'adoptedStyleSheets' property on 'ShadowRoot': Failed to convert value to 'CSSStyleSheet'.

so can you provide a project template for vite?

tks

Unable to perform just-in-time compilation of Tailwind CSS

Compiles only at startup, watch mode does not compile just-in-time, is just-in-time compilation not supported?

Project configuration:

import litcss from 'rollup-plugin-lit-css';
import postcssConfig from 'postcss-load-config';
const config = await postcssConfig();

plugins: [
  litcss({ transform: (css, { filePath }) => postcss(config.plugins).process(css, { from: filePath }).css }),
]

postcss.config.js

import tailwindcss from 'tailwindcss';
export default {
  plugins: [tailwindcss],
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.