@pwrs/vite-plugin-lit-css 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { Options } from '@pwrs/lit-css/lit-css';
3
+ import { type FilterPattern } from '@rollup/pluginutils';
4
+ export interface LitCSSOptions extends Omit<Options, 'css'> {
5
+ /**
6
+ * Files to include for transformation
7
+ * @default /\.css$/i
8
+ */
9
+ include?: FilterPattern;
10
+ /**
11
+ * Files to exclude from transformation
12
+ */
13
+ exclude?: FilterPattern;
14
+ }
15
+ /**
16
+ * Vite plugin to import CSS files as tagged template literals
17
+ *
18
+ * @param options - Plugin configuration options
19
+ * @returns Vite plugin
20
+ */
21
+ export declare function litCSS(options?: LitCSSOptions): Plugin;
22
+ export default litCSS;
@@ -0,0 +1,53 @@
1
+ import { createFilter } from "@rollup/pluginutils";
2
+ import { transform } from "@pwrs/lit-css";
3
+ import { readFile } from "node:fs/promises";
4
+ function litCSS(options) {
5
+ const {
6
+ exclude,
7
+ include = /\.css$/i,
8
+ specifier,
9
+ tag,
10
+ ...rest
11
+ } = options ?? {};
12
+ const filter = createFilter(include, exclude);
13
+ return {
14
+ name: "@pwrs/vite-plugin-lit-css",
15
+ enforce: "pre",
16
+ // Run before Vite's built-in CSS plugin
17
+ async resolveId(source, importer, options2) {
18
+ if (!importer) return null;
19
+ if (!source.endsWith(".css") && !source.endsWith(".scss") && !source.endsWith(".sass") && !source.endsWith(".less") && !source.endsWith(".styl"))
20
+ return null;
21
+ const resolution = await this.resolve(source, importer, {
22
+ skipSelf: true,
23
+ // Don't call ourselves recursively
24
+ ...options2
25
+ });
26
+ if (!resolution || resolution.external) return null;
27
+ if (filter(resolution.id)) {
28
+ return `\0${resolution.id}.lit-css.js`;
29
+ }
30
+ return null;
31
+ },
32
+ async load(id) {
33
+ if (!id.includes(".lit-css.js")) return null;
34
+ const cleanId = id.replace(/^\0/, "").replace(/\.lit-css\.js$/, "");
35
+ try {
36
+ const css = await readFile(cleanId, "utf8");
37
+ const code = await transform({ css, specifier, tag, filePath: cleanId, ...rest });
38
+ return {
39
+ code,
40
+ map: { mappings: "" }
41
+ };
42
+ } catch (error) {
43
+ this.error(error?.message ?? String(error));
44
+ }
45
+ }
46
+ };
47
+ }
48
+ var vite_plugin_lit_css_default = litCSS;
49
+ export {
50
+ vite_plugin_lit_css_default as default,
51
+ litCSS
52
+ };
53
+ //# sourceMappingURL=vite-plugin-lit-css.js.map