Skip to content

Instantly share code, notes, and snippets.

@searls
Last active March 6, 2024 19:37
Show Gist options
  • Save searls/d9ca494792736f94d765223c6ba98d33 to your computer and use it in GitHub Desktop.
Save searls/d9ca494792736f94d765223c6ba98d33 to your computer and use it in GitHub Desktop.
const css4ColorsToLegacyRgbaPlugin = {
postcssPlugin: 'these-colors-dont-run',
Once (root) {
root.walkDecls((decl) => {
const rgbRegex = /rgb\((\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*(?:\/\s*(\d+\.?\d*))?\)/g
decl.value = decl.value.replace(rgbRegex, (match, r, g, b, a) => {
if (!a || a === '1' || a === '1.0') {
return `rgb(${r}, ${g}, ${b})`
} else {
return `rgba(${r}, ${g}, ${b}, ${a})`
}
})
})
}
}
module.exports = (api) => {
return {
plugins: [
require('postcss-import'),
require('tailwindcss')({
config: './config/tailwind.config.mailer.js'
}),
require('postcss-css-variables'),
css4ColorsToLegacyRgbaPlugin
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment