Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
postcss-unit-unit
Advanced tools
A CSS post-processor that converts px to viewport units (vw, vh, rpx, rem, vmin, vmax, ...).
该插件是基于 postcss-px-to-viewport 改造的 CSS 单位转换工具,由 Postcss8.x 版本接口实现,可支持任意单位转为任意单位。
注意:配置参数 fullViewportWidth
为目标单位总宽度,如目标单位为 rpx
时填写 750
, 目标单位为 vw
时填写 100
,其他情况根据比例计算。
npm install postcss-unit-unit --save-dev
{
"unitToConvert": "px",
"viewportWidth": 375,
"unitPrecision": 5,
"viewportUnit": "rpx",
"fontViewportUnit": "rpx",
"fullViewportWidth": 750,
"selectorBlackList": [],
"propList": ["*"],
"minPixelValue": 1,
"mediaQuery": false,
"replace": true,
"landscape": false,
"landscapeUnit": "vw",
"landscapeWidth": 568
}
unitToConvert
(String) 需要转换的单位,默认为"px"viewportWidth
(Number) 设计稿的视口宽度unitPrecision
(Number) 单位转换后保留的精度propList
(Array) 能转化为 vw 的属性列表
传入特定的 CSS 属性;
可以传入通配符""去匹配所有属性,例如:[''];
在属性的前或后添加"",可以匹配特定的属性. (例如['position'] 会匹配 background-position-y)
在特定属性前加 "!",将不转换该属性的单位 . 例如: ['', '!letter-spacing'],将不转换 letter-spacing
"!" 和 ""可以组合使用, 例如: ['', '!font*'],将不转换 font-size 以及 font-weight 等属性viewportUnit
(String) 希望使用的视口单位fontViewportUnit
(String) 字体使用的视口单位selectorBlackList
(Array) 需要忽略的 CSS 选择器,不会转为视口单位,使用原有的 px 等单位。
如果传入的值为字符串的话,只要选择器中含有传入值就会被匹配
例如 selectorBlackList 为 ['body'] 的话, 那么 .body-class 就会被忽略
如果传入的值为正则表达式的话,那么就会依据 CSS 选择器是否匹配该正则
例如 selectorBlackList 为 [/^body$/] , 那么 body 会被忽略,而 .body 不会minPixelValue
(Number) 设置最小的转换数值,如果为 1 的话,只有大于 1 的值会被转换mediaQuery
(Boolean) 媒体查询里的单位是否需要转换单位replace
(Boolean) 是否直接更换属性值,而不添加备用属性exclude
(Array or Regexp) 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
如果值是一个正则表达式,那么匹配这个正则的文件会被忽略
如果传入的值是一个数组,那么数组里的值必须为正则include
(Array or Regexp) 如果设置了 include,那将只有匹配到的文件才会被转换,例如只转换 'src/mobile' 下的文件 (include: //src/mobile//)
如果值是一个正则表达式,将包含匹配的文件,否则将排除该文件
如果传入的值是一个数组,那么数组里的值必须为正则landscape
(Boolean) 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)landscapeUnit
(String) 横屏时使用的单位landscapeWidth
(Number) 横屏时使用的视口宽度// postcss.config.js
module.exports = {
plugins: {
"postcss-unit-unit": {
viewportWidth: 375,
},
},
};
// vite.config.js
import PxToViewport from "postcss-unit-unit";
export default defineConfig({
css: {
postcss: {
plugins: [
PxToViewport({
viewportWidth: 375,
}),
],
},
},
});
FAQs
A CSS post-processor that converts px to viewport units (vw, vh, rpx, rem, vmin, vmax, ...).
We found that postcss-unit-unit demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.