-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
rollup-plugin-lit-css.ts
47 lines (39 loc) · 1.1 KB
/
rollup-plugin-lit-css.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { Plugin } from 'rollup';
import type { Options } from '@pwrs/lit-css/lit-css';
import { createFilter, type FilterPattern } from '@rollup/pluginutils';
import { transform } from '@pwrs/lit-css';
import { resolve } from 'node:path';
export interface LitCSSOptions extends Omit<Options, 'css'> {
include?: FilterPattern;
exclude?: FilterPattern;
}
export function litCss(options?: LitCSSOptions): Plugin {
const {
exclude,
include = /\.css$/i,
specifier,
tag,
...rest
} = options ?? {};
const filter = createFilter(include, exclude);
return {
name: 'lit-css',
load(id): null {
if (filter(id)) this.addWatchFile(resolve(id));
return null;
},
async transform(css, id) {
if (!filter(id)) return null;
try {
const code = await transform({ css, specifier, tag, filePath: id, ...rest });
return { code, map: { mappings: '' } };
} catch (error) {
this.error(error.message, {
column: parseInt(error.column),
line: parseInt(error.line),
});
}
},
};
}
export default litCss;