-
Notifications
You must be signed in to change notification settings - Fork 0
/
css.js
44 lines (37 loc) · 1.09 KB
/
css.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
// https://github.com/tailwindlabs/tailwindcss/discussions/11851
import postcss from 'postcss'
import tailwind from 'tailwindcss'
import cssnano from 'cssnano'
import autoprefixer from 'autoprefixer'
import baseConfig from './tailwind.config'
import { watch, promises as fs } from 'node:fs'
import { argv } from 'node:process'
const dirname = import.meta.dirname ?? import.meta.dir ?? '.'
const args = argv.slice(2)
const source = [
'@tailwind base',
'@tailwind components',
'@tailwind utilities'
].join(';')
const plugins = [
tailwind({ presets: [baseConfig] }),
cssnano({ preset: 'default', plugins: [autoprefixer] })
]
const build = async () => {
const { css } = await postcss(plugins).process(source)
await fs.mkdir(`${dirname}/dist/`, { recursive: true })
await fs.writeFile(
`${dirname}/dist/css.json`,
JSON.stringify({ css }, null, ' ')
)
console.log('Rebuild CSS file')
}
if (args.includes('--watch')) {
build()
watch(`${dirname}/src`, (type, file) => {
console.log(`${new Date().toISOString()}: ${type} file: ./src/${file}`)
build()
})
} else {
build()
}