postcss-pixel-to-viewport
A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units.
Usage
If your project involves a fixed width, this script will help to convert pixels into viewport units.
Input/Output
// {} // {}
Example
'use strict'; var fs = ;var postcss = ;var px2viewport = ;var css = fs;var options = propertyBlacklist: 'font-size';var processedCss = css; fs;
Options
Default:
viewportWidth: 750 viewportUnit: 'vmin' propertyBlacklist: minPixelValue: 2 enableConvertComment: 'on' disableConvertComment: 'off' mediaQuery: false
viewportWidth
(Number) The width of the viewport.viewportUnit
(String) Expected units.propertyBlacklist
(Array) The propertys to ignore and leave as px.- If value is string, it checks to see if property contains the string.
['font']
will matchfont-size
- If value is regexp, it checks to see if the property matches the regexp.
[/^font$/]
will matchfont
but notfont-size
- If value is string, it checks to see if property contains the string.
minPixelValue
(Number) Set the minimum pixel value to replace.enableConvertComment
(String) content of comment for enable convert px unit before the declaration.disableConvertComment
(String) content of comment for disable convert px unit before the declaration.mediaQuery
(Boolean) Allow px to be converted in media queries.
Use comment to enable/disable convert px value for single declaration
font-size: 14px;/*on*/
comment before the declaration will convert px to viewport unit, iffont-size
is in your property blacklist but you want to convert this single declaration.font-size: 14px;/*off*/
comment before the declaration will not convert px unit.
Use with gulp-postcss
var gulp = ;var postcss = ;var px2viewport = ; gulp;