YesPlayMusic/packages/web/postcss.config.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-var-requires */
const { colord } = require('colord')
const colors = require('tailwindcss/colors')
2022-05-01 19:53:25 +08:00
const replaceBrandColorWithCSSVar = () => {
const blues = Object.entries(colors.blue).map(([key, value]) => {
2022-05-29 17:53:27 +08:00
const rgb = colord(value).toHsl()
const hsl = colord(value).toHsl()
return {
key,
2022-05-29 17:53:27 +08:00
hsl: `${hsl.h} ${hsl.s} ${hsl.l}`,
rgb: `${rgb.r} ${rgb.g} ${rgb.b}`,
}
})
return {
2022-05-01 19:53:25 +08:00
postcssPlugin: 'replaceBrandColorWithCSSVar',
Declaration(decl) {
let value = decl.value
blues.forEach(blue => {
2022-04-29 19:16:34 +08:00
if (decl?.parent?.selector?.includes('-blue-')) {
return
}
2023-03-26 02:16:01 +08:00
value = value.replace(`rgb(${blue.rgb}`, `hsl(var(--brand-color-${blue.key})`)
})
// if (decl.value !== value) {
// console.log({
// before: decl.value,
// after: value,
// })
// }
decl.value = value
},
}
}
2022-05-01 19:53:25 +08:00
replaceBrandColorWithCSSVar.postcss = true
2022-03-13 14:40:38 +08:00
module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
2022-05-13 23:33:11 +08:00
// replaceBrandColorWithCSSVar,
],
2022-03-13 14:40:38 +08:00
}