postcss-font-weight
v1.0.0
Published
PostCSS plugin to convert font-weight numbers > 500 to bold
Downloads
12
Maintainers
Readme
postcss-font-weight
PostCSS插件,用于处理字重问题,将数字超过500的font-weight值直接改为bold,以减少兼容性问题。
功能
- 将font-weight值大于等于500的数字转换为bold
- 保持其他值不变(包括400和已经是bold的值)
- 提高CSS的兼容性
安装
npm install postcss-font-weight --save-dev使用
基本使用
const postcss = require("postcss");
const fontWeightPlugin = require("postcss-font-weight");
postcss([fontWeightPlugin()])
.process(css)
.then((result) => {
console.log(result.css);
});在PostCSS配置中使用
postcss.config.js
module.exports = {
plugins: [require("postcss-font-weight")],
};输入/输出示例
输入
.test1 {
font-weight: 400;
}
.test2 {
font-weight: 500;
}
.test3 {
font-weight: 600;
}
.test4 {
font-weight: 700;
}
.test5 {
font-weight: bold;
}输出
.test1 {
font-weight: 400;
}
.test2 {
font-weight: 500;
}
.test3 {
font-weight: bold;
}
.test4 {
font-weight: bold;
}
.test5 {
font-weight: bold;
}兼容性
该插件适用于所有支持PostCSS的环境,包括:
- Node.js
- 浏览器
- 构建工具(如Webpack、Gulp等)
许可证
ISC
