Registry / web-framework / vite-plugin-lit-css

vite-plugin-lit-css

JSON →
library2.2.2jsnpmunverified

Vite plugin that transforms CSS/SCSS imports into Lit-compatible CSSResult or CSSResultGroup objects via constructible stylesheets. Current stable version is 2.2.2, released monthly. Designed exclusively for LitElement projects using Vite, it supports SASS/SCSS and PostCSS preprocessing. Unlike generic CSS handling, it outputs Lit template-literal stylesheets directly. Requires Lit 2/3 and Vite 5–7. TypeScript definitions included. Known limitation: HMR triggers full page reload.

npm install vite-plugin-lit-css
INSTALL
IMPORT
SIG · VITE-PLUGIN-LIT-CS
V
vite-plugin-lit-css
web-frameworkjavascriptv2.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import litCss from 'vite-plugin-lit-css'
const litCss = require('vite-plugin-lit-css')
ESM-only. CommonJS require will fail.
CSSResult
import styles from './styles.css'
const styles = require('./styles.css')
Imports CSS as a Lit CSSResult object. Must be used in LitElement's static styles property.
TypeScript types
/// <reference types="vite-plugin-lit-css/client" />
/// <reference types="vite/client" /> before vite-plugin-lit-css/client
Type augmentation must be declared before vite/client types for proper CSS module declarations.

Shows how to configure the plugin with Vite and import a CSS file as a Lit stylesheet.

// vite.config.ts import { defineConfig } from 'vite'; import litCss from 'vite-plugin-lit-css'; export default defineConfig({ plugins: [ litCss({ exclude: ['./src/global.css'], }), ], }); // src/my-element.ts import { LitElement, html } from 'lit'; import styles from './styles.css'; export class MyElement extends LitElement { static styles = [styles]; render() { return html`<p>Hello World</p>`; } } declare global { interface HTMLElementTagNameMap { 'my-element': MyElement; } } customElements.define('my-element', MyElement);
Debug
Known issues
breakingvite-plugin-lit-css v2 drops support for Vite 4. Upgrade to Vite 5+.
fix
Update Vite to ^5.2.10 || ^6.0.0 || ^7.0.0
affects: >=2.0.0
breakingvite-plugin-lit-css v2 requires Node.js >=18.2.0.
fix
Update Node.js to v18.2.0 or later.
affects: >=2.0.0
gotchaHMR is not supported; every change triggers a full page reload.
fix
No workaround; consider using a different approach if HMR is critical.
affects: >=1.0.0
gotchaGlobal stylesheets (e.g., index.css) must be excluded via the exclude option, otherwise they will be transformed into Lit styles incorrectly.
fix
Add global CSS files to the exclude option in the plugin configuration.
affects: >=1.0.0
deprecatedvite-plugin-lit-css 1.x (for Vite 4) is deprecated.
fix
Upgrade to v2 and migrate to Vite 5+.
affects: 1.x
Errors
Common errors & fixes
Cannot find module 'vite-plugin-lit-css' or its corresponding type declarations.
Missing dependency or wrong Node version (<18.2.0).
fix
Run 'npm install -D vite-plugin-lit-css' and ensure Node >=18.2.0.
The request url failed: The request url failed with error code 404. Vite is not running.
CommonJS require() used in an ESM-only package.
fix
Use 'import litCss from 'vite-plugin-lit-css'' instead of require().
TypeScript: Property 'styles' does not exist on type 'typeof import('./styles.css')'.
Missing or incorrect TypeScript type augmentation.
fix
Add '/// <reference types="vite-plugin-lit-css/client" />' before vite/client in your vite-env.d.ts.
Upgrade
Version history
2.2.2latest on npm
Audit
Dependencies
litrequiredPeer dependency: provides CSSResult and constructible stylesheet APIs
viterequiredPeer dependency: requires Vite's plugin system and CSS processing
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
vite-plugin-lit-css — npm install vite-plugin-lit-css · libregistry