Package Exports
- @mega-apps/postcss-theme-helper
- @mega-apps/postcss-theme-helper/unplugin
Readme
@mega-apps/postcss-theme-helper
PostCSS 主题助手
特性
- 支持主题颜色替换
- 提供Webpack插件,自动注入主题替换代码
安装
yarn add @mega-apps/postcss-theme-helper --dev
使用说明
Nuxt.js 项目
// nuxt.config.js
build: {
plugins: [
// 引入自动注入代码
require('@mega-apps/postcss-theme-helper/unplugin').default.webpack({debug: false})
],
postcss: {
postcss: {
plugins: {
"@mega-apps/postcss-theme-helper": {
debug: false,
colorVariableReplacer: [
// 类似于CSS的解析,从上而下,最小优先级最高
{
matchColors: ["black", "rgb(239, 68, 68)"],
initVarColors: ["red", "blue"],
strict: true,
cssVarPrefix: "--myColor",
wrapper: ":root",
},
{
matchColors: ["black"],
initVarColors: ["yellow"],
strict: true,
cssVarPrefix: "--hiColor",
wrapper: "div",
},
],
},
},
// 调整postcss插件的次序,参照文档:https://nuxtjs.org/docs/configuration-glossary/configuration-build#postcss
// 插件必须在 tailwindcss 之后,这样才能对tailwindcss的样式进行处理替换
order: ["tailwindcss", "@mega-apps/postcss-theme-helper"],
},
}
}