unplugin to allow .scss files to be imported as css variables in lit.
pnpm add unplugin-lit-sassvite
vite.config.ts
import { defineConfig } from "vite";
import { unpluginLitSass } from "unplugin-lit-sass";
export default defineConfig({
plugins: [unpluginLitSass.vite()],
});src/vite-env.d.ts
/// <reference types="unplugin-lit-sass/@types" />Create .scss.
e.g.) lit-component-name.scss.
Warning
The path name must end with ?litSass.
Giving this query will run the plugin
import styles from "./lit-component-name.scss?litSass";
// or
import { styles } from "./lit-component-name.scss?litSass";import styles from "./my-element.scss?litSass";
@customElement("my-element")
export class MyElement extends LitElement {
static readonly styles: CSSResultArray = [styles];
// ...
render() {
// ...
}
}File type to be processed.
[".scss", ".sass"]
Array<`.${string}` | `?${string}`>
export type Options = {
/**
* File type to be processed.
*
* @default [".scss", ".sass"]
*/
fileType?: Array<`.${string}` | `?${string}`>;
};