generated from dev-protocol/template-repos-ts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.plugin.tw.js
49 lines (45 loc) · 1.13 KB
/
rollup.plugin.tw.js
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
/* eslint-disable functional/no-expression-statement */
/* eslint-disable functional/no-conditional-statement */
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: [...purgeFiles], separator: ':' },
}),
autoprefixer,
]
return postcss(plugins).process('@tailwind utilities;', {
from: undefined,
to: undefined,
})
}
const defaultOptions = {
include: undefined,
exclude: undefined,
}
const placeholder = '<style 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,
`<style>${result.css.replace(/:/g, '\\:')}`,
)
}
return null
}
return null
},
}
}