postcss rem to responsive pixel
1.0.0
重要的
代码已移至Sonofmagic/Postcss-Plugins,此存储库已存档!
用于从REM单元生成PX或RPX单元的PostCSS插件。
typescript
重写并经过良好的测试。px
和rpx
!如果您仍然使用
[email protected]
,则应使用[email protected]
到响应[email protected]
npm i -D postcss-rem-to-responsive-pixel
yarn add -D postcss-rem-to-responsive-pixel
pnpm i -D postcss-rem-to-responsive-pixel
// postcss.config.js
module . exports = {
plugins : [
// for example
// require('autoprefixer'),
// require('tailwindcss'),
require ( 'postcss-rem-to-responsive-pixel' ) ( {
rootValue : 32 ,
propList : [ '*' ] ,
transformUnit : 'rpx' ,
} ) ,
] ,
}
当您使用tailwindcss
编写您的网站或微图时,默认单元为rem
,因此有时我们必须将单元转换为px
或rpx
。
// postcss.config.js
module . exports = {
plugins : [
require ( 'tailwindcss' ) ,
require ( 'postcss-rem-to-responsive-pixel' ) ( {
rootValue : 32 ,
propList : [ '*' ] ,
transformUnit : 'rpx' ,
} ) ,
] ,
}
使用默认设置,仅针对字体相关的属性。
// input
h1 {
margin : 0 0 20 px ;
font-size : 2 rem ;
line-height : 1.2 ;
letter-spacing : 0.0625 rem ;
}
// output
h1 {
margin : 0 0 20 px ;
font-size : 64 rpx;
line-height : 1.2 ;
letter-spacing : 2 rpx;
}
类型: Object | Null
默认:
{
rootValue : 16 ,
unitPrecision : 5 ,
selectorBlackList : [ ] ,
propList : [ 'font' , 'font-size' , 'line-height' , 'letter-spacing' ] ,
replace : true ,
mediaQuery : false ,
minRemValue : 0 ,
exclude : [ / node_modules / i ] ,
transformUnit : 'px' ,
disabled : false
}
类型: number
根元素字体大小。
类型: number
允许使用十进制精度PX单元,地板(向下舍入一半)。
类型:( (string | RegExp)[]
可以从REM变为PX的属性。
类型:( (string | RegExp)[]
选择者忽略并以REM离开。
类型: boolean
替换包含REM的规则而不是添加后备。
类型: boolean
允许REM在媒体查询中转换。
类型: number
设置最小REM值以替换。
类型:( (string | RegExp)[] | ((filePath: string) => boolean)
忽略的文件路径并以Px离开。
类型: 'px' | 'rpx'
变换输出单元。
类型: boolean
如果禁用此插件。
当前,忽略单个财产的最简单方法是在REM单位声明中使用资本。
// `rem` is converted to `px`
. convert {
font-size : 1 rem ; // converted to 16px
}
// `Rem` or `REM` is ignored by `postcss-rem-to-pixel` but still accepted by browsers
. ignore {
border : 1 rem solid; // ignored
border-width : 2 rem ; // ignored
}
感谢postcss-rem-to-pixel
和postcss-pxtorem
的作者。