postcss-convertpx
forked from postcss-px-to-viewport.
requirement
Must set this plugin after postcss-nested.
Usage
If your project involves a fixed width, this script will help to convert pixels into viewport units.
Input/Output
//{} //{}
Example
'use strict';const postcss = ;const p2v = ;const fs = ; const css = fs; ;
Options
Default:
viewportWidth: 750 unitPrecision: 5 viewportUnit: 'vw' convertFont: false minPixelValue: 1 mediaQuery: false convertLineHeight: true declarationBlackList: undefined scale: undefined exclude: undefined
viewportWidth
(Number) The width of the viewport.unitPrecision
(Number) The decimal numbers to allow the REM units to grow to.viewportUnit
(String) Expected units.convertFont
(Boolean) Allow px to be converted infont
/font-size
.minPixelValue
(Number) Set the minimum pixel value to replace.mediaQuery
(Boolean) Allow px to be converted in media queries.convertLineHeight
(Boolean) Allow px to be converted infont
/line-height
.declarationBlackList
(string[]) The declarations to ignore and leave as px. Note, if use short-hand likefont
will only ignorefont
notfont-size
, so if you want ignorefont
andfont-size
, you should specify both like thisdeclarationBlackList: ['font', 'font-size']
.scale
(Number) forvw
will calculate automatic according toviewportWidth
. for other unit such asrem
, you can specifyscale
likescale: 75
, then1rem = 75px
.exclude(filepath)
(Function) You can exclude some file by specify this option, which returns a boolean, iftrue
will be excluded.
Skip a declaration
input
{}
output
{}
width
will be ignored.
Skip a rule
input
/* skip-p2v */{}
output
/* skip-p2v */{}
The rule div
will be ignored.
Skip a media query condition
input
/* skip-p2v */{}
output
/* skip-p2v */{}
By default, will not convert media query condition, but if you specify mediaQuery: true
, this comment would be useful.