generated from dev-protocol/template-repos-ts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.plugin.tw.mjs
51 lines (47 loc) · 1.1 KB
/
rollup.plugin.tw.mjs
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
48
49
50
51
import { createFilter } from '@rollup/pluginutils'
import postcss from 'postcss'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
function transform(purgeFiles) {
const plugins = [
tailwindcss({
config: {
content: {
files: [...purgeFiles],
transform: (content) =>
content.replace('static styles = ', 'styles ='),
},
separator: ':',
},
}),
autoprefixer,
]
return postcss(plugins).process('@tailwind utilities;', {
from: undefined,
to: undefined,
})
}
const defaultOptions = {
include: undefined,
exclude: undefined,
}
const placeholder = '/*_tailwind_*/'
export default function litTailwindcss(options = defaultOptions) {
const filter = createFilter(options.include, options.exclude)
const ids = new Set()
return {
moduleParsed({ id }) {
if (filter(id)) ids.add(id)
},
async renderChunk(code) {
if (code.includes(placeholder)) {
const result = await transform(Array.from(ids))
if (result.css) {
return code.replace(placeholder, `${result.css.replace(/:/g, '\\:')}`)
}
return null
}
return null
},
}
}