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-color-replace
Advanced tools
- 替换css文件中的颜色 或者 自定替换css 的属性;搭配 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'
import path from 'path'
export default () => {
return {
plugins: [
replaceColorPlugin({
colorVariables: {
// 定义 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)",
},
styleId: "_VITE_REPLACE_COLOR_", // 注入自定义css 内容 时 style标签名
includes: ["src/**/App.vue*"], // vue文件编译处理后 样式文件路径可能并不是 .vue 结尾
exclude: ["node_modules/**"], // 忽略 依赖包
}),
],
}
}
.color {
color: #2563f4;
background-color: rgb(#2563f4, 0.4); // 有透明度 会从 rgb 属性中去匹配
box-shadow: 0 0 1px rgb(37 99 244);
border-color: #2563f466; // 8位带颜色的 也会从 rgb 属性中去匹配
}
.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);
}
参数 | 类型 | 默认值/参数 | 必填 | 说明 |
---|---|---|---|---|
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 | - | 否 | 忽略文件规则 |
import { injectStyle } from "vite-plugin-replace-theme/es/client";
injectStyle(`:root { --c5-color: #2563F4; --c5-rgb: 37 99 244;}`)
FAQs
- 替换css文件中的颜色 或者 自定替换css 的属性;搭配 css变量可实现动态切换主题色
We found that vite-plugin-color-replace 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.