Gathering detailed insights and metrics for postcss-px-to-viewport-copy
Gathering detailed insights and metrics for postcss-px-to-viewport-copy
Gathering detailed insights and metrics for postcss-px-to-viewport-copy
Gathering detailed insights and metrics for postcss-px-to-viewport-copy
A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units. The best choice to create a scalable interface on different displays by one design size.
npm install postcss-px-to-viewport-copy
Typescript
Module System
Node Version
NPM Version
JavaScript (94.62%)
CSS (5.38%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3,144 Stars
71 Commits
412 Forks
54 Watchers
14 Branches
28 Contributors
Updated on Jul 10, 2025
Latest Version
1.1.1
Package Id
postcss-px-to-viewport-copy@1.1.1
Unpacked Size
33.95 kB
Size
10.87 kB
File Count
13
NPM Version
8.19.3
Node Version
18.13.0
Published on
Jan 28, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
English | 中文
A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units.
If your project involves a fixed width, this script will help to convert pixels into viewport units.
1.class { 2 margin: -10px .5vh; 3 padding: 5vmin 9.5px 1px; 4 border: 3px solid black; 5 border-bottom-width: 1px; 6 font-size: 14px; 7 line-height: 20px; 8} 9 10.class2 { 11 padding-top: 10px; /* px-to-viewport-ignore */ 12 /* px-to-viewport-ignore-next */ 13 padding-bottom: 10px; 14 /* Any other comment */ 15 border: 1px solid black; 16 margin-bottom: 1px; 17 font-size: 20px; 18 line-height: 30px; 19} 20 21@media (min-width: 750px) { 22 .class3 { 23 font-size: 16px; 24 line-height: 22px; 25 } 26}
1.class { 2 margin: -3.125vw .5vh; 3 padding: 5vmin 2.96875vw 1px; 4 border: 0.9375vw solid black; 5 border-bottom-width: 1px; 6 font-size: 4.375vw; 7 line-height: 6.25vw; 8} 9 10.class2 { 11 padding-top: 10px; 12 padding-bottom: 10px; 13 /* Any other comment */ 14 border: 1px solid black; 15 margin-bottom: 1px; 16 font-size: 6.25vw; 17 line-height: 9.375vw; 18} 19 20@media (min-width: 750px) { 21 .class3 { 22 font-size: 16px; 23 line-height: 22px; 24 } 25}
Add via npm
$ npm install postcss-px-to-viewport --save-dev
or yarn
$ yarn add -D postcss-px-to-viewport
Default Options:
1{ 2 unitToConvert: 'px', 3 viewportWidth: 320, 4 unitPrecision: 5, 5 propList: ['*'], 6 viewportUnit: 'vw', 7 fontViewportUnit: 'vw', 8 selectorBlackList: [], 9 minPixelValue: 1, 10 mediaQuery: false, 11 replace: true, 12 exclude: undefined, 13 include: undefined, 14 landscape: false, 15 landscapeUnit: 'vw', 16 landscapeWidth: 568 17}
unitToConvert
(String) unit to convert, by default, it is px.viewportWidth
(Number) The width of the viewport.unitPrecision
(Number) The decimal numbers to allow the vw units to grow to.propList
(Array) The properties that can change from px to vw.
viewportUnit
(String) Expected units.fontViewportUnit
(String) Expected units for font.selectorBlackList
(Array) The selectors to ignore and leave as px.
['body']
will match .body-class
[/^body$/]
will match body
but not .body
minPixelValue
(Number) Set the minimum pixel value to replace.mediaQuery
(Boolean) Allow px to be converted in media queries.replace
(Boolean) replaces rules containing vw instead of adding fallbacks.exclude
(Regexp or Array of Regexp) Ignore some files like 'node_modules'
include
(Regexp or Array of Regexp) If include
is set, only matching files will be converted,
for example, only files under src/mobile/
(include: /\/src\/mobile\//
)
landscape
(Boolean) Adds @media (orientation: landscape)
with values converted via landscapeWidth
.landscapeUnit
(String) Expected unit for landscape
optionlandscapeWidth
(Number) Viewport width for landscape orientation.
exclude
andinclude
can be set together, and the intersection of the two rules will be taken.
You can use special comments for ignore conversion of single lines:
/* px-to-viewport-ignore-next */
— on a separate line, prevents conversion on the next line./* px-to-viewport-ignore */
— after the property on the right, prevents conversion on the same line.Example:
1/* example input: */ 2.class { 3 /* px-to-viewport-ignore-next */ 4 width: 10px; 5 padding: 10px; 6 height: 10px; /* px-to-viewport-ignore */ 7 border: solid 2px #000; /* px-to-viewport-ignore */ 8} 9 10/* example output: */ 11.class { 12 width: 10px; 13 padding: 3.125vw; 14 height: 10px; 15 border: solid 2px #000; 16}
There are several more reasons why your pixels may not convert, the following options may affect this:
propList
, selectorBlackList
, minPixelValue
, mediaQuery
, exclude
, include
.
add to your postcss.config.js
1module.exports = { 2 plugins: { 3 // ... 4 'postcss-px-to-viewport': { 5 // options 6 } 7 } 8}
add to your gulpfile.js
:
1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3var pxtoviewport = require('postcss-px-to-viewport'); 4 5gulp.task('css', function () { 6 7 var processors = [ 8 pxtoviewport({ 9 viewportWidth: 320, 10 viewportUnit: 'vmin' 11 }) 12 ]; 13 14 return gulp.src(['build/css/**/*.css']) 15 .pipe(postcss(processors)) 16 .pipe(gulp.dest('build/css')); 17});
Please read Code of Conduct and Contributing Guidelines for submitting pull requests to us.
In order to run tests, you need to install dev-packages:
$ npm install
Then run the tests via npm script:
$ npm run test
The changelog is here.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License.
Visit Evrone website to get more information about the projects build.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/11 approved changesets -- score normalized to 4
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
32 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More