Gathering detailed insights and metrics for @minko-fe/postcss-pxtorem
Gathering detailed insights and metrics for @minko-fe/postcss-pxtorem
Gathering detailed insights and metrics for @minko-fe/postcss-pxtorem
Gathering detailed insights and metrics for @minko-fe/postcss-pxtorem
A postcss plugin that converts px to rem. px 转 rem 的 postcss 插件
npm install @minko-fe/postcss-pxtorem
Typescript
Module System
Node Version
NPM Version
72.6
Supply Chain
98.1
Quality
76
Maintenance
100
Vulnerability
99.6
License
TypeScript (96.14%)
CSS (1.89%)
JavaScript (1.42%)
HTML (0.55%)
Total Downloads
30,543
Last Day
13
Last Week
203
Last Month
797
Last Year
6,855
MIT License
64 Stars
129 Commits
6 Forks
4 Watchers
2 Branches
1 Contributors
Updated on Jul 01, 2025
Minified
Minified + Gzipped
Latest Version
1.5.0
Package Id
@minko-fe/postcss-pxtorem@1.5.0
Unpacked Size
85.33 kB
Size
14.30 kB
File Count
9
NPM Version
10.5.0
Node Version
18.20.2
Published on
Apr 30, 2024
Cumulative downloads
Total Downloads
Last Day
-13.3%
13
Compared to previous day
Last Week
8%
203
Compared to previous week
Last Month
10.8%
797
Compared to previous month
Last Year
-45.2%
6,855
Compared to previous year
1
English | 中文
A plugin for PostCSS that generates rem units from pixel units.
If you don't need the following new features, you can use the official library: postcss-pxtorem
postcss-pxtorem
supported option in style files1npm install postcss @minko-fe/postcss-pxtorem -D
Pixels are the easiest unit to use (opinion). The only issue with them is that they don't let browsers change the default font size of 16. This script converts every px value to a rem from the properties you choose to allow the browser to set the font size.
1// postcss.config.js 2import pxtorom from '@minko-fe/postcss-pxtorem' 3 4export default { 5 plugins: [ 6 pxtorom({ 7 rootValue: 16, 8 selectorBlackList: ['some-class'], 9 propList: ['*'], 10 atRules: ['media'], 11 // ... 12 }), 13 ], 14}
Name | Type | Default | Description |
---|---|---|---|
rootValue | number | ((input: Input) => number) | 16 | Represents the root element font size or returns the root element font size based on the input parameter |
unitToConvert | string | px | unit to convert, by default, it is px |
unitPrecision | number | 5 | The decimal numbers to allow the REM units to grow to. |
propList | string[] | ['*'] | The properties that can change from px to rem. Refer to: propList |
selectorBlackList | (string | RegExp)[] | [] | The selectors to ignore and leave as px. Refer to: selectorBlackList |
replace | boolean | true | Replaces rules containing rems instead of adding fallbacks. |
atRules | boolean | string[] | false | Allow px to be converted in at-rules. Refer to At-rule |
minPixelValue | number | 0 | Set the minimum pixel value to replace. |
exclude | string | RegExp | ((filePath: string) => boolean) | null | /node_modules/i | The file path to ignore and leave as px. Refer to: exclude |
include | string | RegExp | ((filePath: string) => boolean) | null | null | The file path to convert px to rem, in contrast to exclude , priority lower than exclude . |
disable | boolean | false | disable plugin, used to disable plugin dynamically |
convertUnit | ConvertUnit | ConvertUnit[] | false | false | convert unit when plugin process end |
*
to enable all properties. Example: ['*']
*
at the start or end of a word. (['*position*']
will match background-position-y
)!
to not match a property. Example: ['*', '!letter-spacing']
['*', '!font*']
['body']
will match .body-class
[/^body$/]
will match body
but not .body
'exclude'
will match \project\postcss-pxtorem\exclude\path
/exclude/i
will match \project\postcss-pxtorem\exclude\path
function (file) { return file.includes('exclude') }
1/* pxtorem?disable=true */ 2.rule { 3 font-size: 15px; // 15px 4}
1/* pxtorem?rootValue=32 */ 2.rule { 3 font-size: 30px; // 0.9375rem 4}
The above is just a simple example, you can set any of the options supported by postcss-pxtorem
in the css file
You may have seen that the css comment is very much like the browser url?. That's right. For the specification, just refer to: query-string
1/* pxtorem?disable=false&rootValue=32&propList[]=*&replace=false&selectorBlackList[]=/some-class/i */
1.rule { 2 /* pxtorem-disable-next-line */ 3 font-size: 15px; // 15px 4}
If you write 15PX
(as long as it's not px
), the plugin also ignores it, because unitToConvert
defaults to px
If you want to use PX
to ignore and want the final unit to be px
, you can:
1// postcss.config.js 2import pxtorem from '@minko-fe/postcss-pxtorem' 3 4export default { 5 plugins: [ 6 pxtorem({ 7 convertUnit: { 8 source: /px$/i, 9 target: 'px', 10 }, 11 }), 12 ], 13}
1import { flexible } from 'modern-flexible' 2 3flexible({ 4 rootValue: 16, 5 distinctDevice: [ 6 { isDevice: (w: number) => w < 750, UIWidth: 375, deviceWidthRange: [375, 750] }, 7 { isDevice: (w: number) => w >= 750, UIWidth: 1920, deviceWidthRange: [1080, 1920] }, 8 ], 9})
@tcstory/postcss-px-to-viewport
A CSS post-processor that converts px to viewport: postcss-pxtoviewport
If this has helped you, please don't hesitate to give a STAR, thanks! 😎
MIT
No vulnerabilities found.
No security vulnerabilities found.