Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
vite-plugin-replace-color
Advanced tools
- 替换css文件中的颜色或者自定替换css属性的vite插件;搭配 css变量可实现动态切换主题色
node version: >=16.0.0
vite version: >=3.0.0
npm i vite-plugin-replace-color -D
# or
yarn add vite-plugin-replace-color -D
# or
pnpm install vite-plugin-replace-color -D
import replaceColorPlugin from 'vite-plugin-replace-color'
export default () => {
return {
plugins: [
replaceColorPlugin({
colorVariables: {
// 颜色需要小写 #FFF 需要写成 #fff
// 定义 rgb 时 会替换 rgb() 里面的 内容 透明度不会修改
// color: #fff --> color: var(--c5-white)
// backgroud: rgb(255,255,255,0.2) ---> backgroud:rgb(var(--c5-white-rgb)/0.2)
"#fff": { hex: "var(--c5-white)", rgb: "var(--c5-white-rgb)" },
"#2563f4": { hex: "var(--c5-color)", rgb: "var(--c5-rgb)" },
"#409eff": "var(--c5-color)",
},
// 注入自定义css 内容 时 style标签名
styleId: "_VITE_REPLACE_COLOR_",
// vue样式编译处理后 文件名有额外参数 如 xxx.vue?vue&type=style 所以结尾加 * 匹配vue
includes: ["src/**/App.vue*"],
// 忽略 依赖包
exclude: ["node_modules/**"],
// 忽略属性替换
ignoreMark: "ignore color"
}),
],
}
}
.color {
color: #2563f4;
background-color: rgb(#2563f4, 0.4); // 有透明度 会从 rgb 属性中去匹配
box-shadow: 0 0 1px rgb(37 99 244);
border-color: #2563f466; // 8位带颜色的 也会从 rgb 属性中去匹配
outline-color: #2563f4; /* ignore color */ // 结尾用注释写上 ignoreMark 时 会跳过此次处理
}
.color {
color: var(--c5-color);
background-color: rgb(var(--c5-rgb)/0.4);
border-color: rgb(var(--c5-rgb)/0.4);
box-shadow: 0 0 1px var(--c5-color);
outline-color: #2563f4;
}
参数 | 类型 | 默认值/参数 | 必填 | 说明 |
---|---|---|---|---|
colorVariables | Record<string, string | { hex?: string; rgb?: string }> | - | 是 | 声明替换的颜色 |
styleId | string | _VITE_REPLACE_COLOR_ | 否 | 注入自定义css 内容 时 style标签名 |
customerReplaceVariable | (decl) => string | decl(https://postcss.org/api/#declaration) | 否 | 自定义替换css(返回''则删除该条属性) |
includes | Array<string|RegExp>|string|RegExp | - | 否 | 匹配文件规则 |
exclude | Array<string|RegExp>|string|RegExp | - | 否 | 忽略文件规则 |
ignoreMark | string | ignore color | 否 | 忽略标识 |
import { injectStyle } from "vite-plugin-replace-color/es/client";
injectStyle(`:root { --c5-color: #2563F4; --c5-rgb: 37 99 244;}`)
FAQs
- 替换css文件中的颜色或者自定替换css属性的vite插件;搭配 css变量可实现动态切换主题色
We found that vite-plugin-replace-color demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.