
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
@yuo/postcss-px2vw
Advanced tools
升级了 postcss-px-to-viewport, 对您有用的话可 add Star, thks~
支持postcss@8.x
可以将你CSS中的px单位转化为vw,1vw等于1/100视口宽度。
.class {
margin: -10px .5vh;
padding: 5vmin 9.5px 1px;
border: 3px solid black;
border-bottom-width: 1px;
font-size: 14px;
line-height: 20px;
}
.class2 {
border: 1px solid black;
margin-bottom: 1px;
font-size: 20px;
line-height: 30px;
}
@media (min-width: 750px) {
.class3 {
font-size: 16px;
line-height: 22px;
}
}
.class {
margin: -3.125vw .5vh;
padding: 5vmin 2.96875vw 1px;
border: 0.9375vw solid black;
border-bottom-width: 1px;
font-size: 4.375vw;
line-height: 6.25vw;
}
.class2 {
border: 1px solid black;
margin-bottom: 1px;
font-size: 6.25vw;
line-height: 9.375vw;
}
@media (min-width: 750px) {
.class3 {
font-size: 16px;
line-height: 22px;
}
}
使用npm安装
$ npm install @yuo/postcss-px2vw -D
或者使用yarn进行安装
$ yarn add @yuo/postcss-px2vw -D
// vite.config.ts
import { defineConfig } from 'vite';
// plugins
import px2vw from '@yuo/postcss-px2vw';
export default defineConfig(() => {
css: {
postcss: {
px2vw({
// 配置参数
})
}
}
});
默认参数:
{
unitToConvert: 'px',
viewportWidth: 320,
unitPrecision: 5,
propList: ['*'],
viewportUnit: 'vw',
fontViewportUnit: 'vw',
selectorBlackList: [],
minPixelValue: 1,
mediaQuery: false,
replace: true,
exclude: [],
landscape: false,
landscapeUnit: 'vw',
landscapeWidth: 568
}
unitToConvert (String) 需要转换的单位,默认为"px"viewportWidth (Number) 设计稿的视口宽度unitPrecision (Number) 单位转换后保留的精度propList (Array) 能转化为vw的属性列表
viewportUnit (String) 希望使用的视口单位fontViewportUnit (String) 字体使用的视口单位selectorBlackList (Array) 需要忽略的CSS选择器,不会转为视口单位,使用原有的px等单位。
selectorBlackList 为 ['body'] 的话, 那么 .body-class 就会被忽略selectorBlackList 为 [/^body$/] , 那么 body 会被忽略,而 .body 不会minPixelValue (Number) 设置最小的转换数值,如果为1的话,只有大于1的值会被转换mediaQuery (Boolean) 媒体查询里的单位是否需要转换单位replace (Boolean) 是否直接更换属性值,而不添加备用属性exclude (Array or Regexp) 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
landscape (Boolean) 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)landscapeUnit (String) 横屏时使用的单位landscapeWidth (Number) 横屏时使用的视口宽度本项目使用 MIT License.
FAQs
support postcss@v8.x, px2vw
We found that @yuo/postcss-px2vw demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.