Socket
Book a DemoInstallSign in
Socket

postcss-px-to-upx

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

postcss-px-to-upx

A CSS post-processor that converts px to uni-app units (rpx, upx).

0.0.1
unpublished
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

postcss-px-to-viewport

NPM version

English | 中文

A plugin for PostCSS that generates uniapp units (rpx, upx) from pixel units.

Input

.class {
  margin: -10DP .5DP;
  padding: 5DP 9.5DP 1px;
  border: 3DP solid black;
  border-bottom-width: 1px;
  font-size: 14DP;
  line-height: 20DP;
}

Output

.class {
  margin: -3.125rpx .5rpx;
  padding: 5rpx 2.96875rpx 1px;
  border: 0.9375rpx solid black;
  border-bottom-width: 1px;
  font-size: 4.375rpx;
  line-height: 6.25rpx;
}

Getting Started

Installation

Add via npm

$ npm install postcss-px-to-upx --save-dev

or yarn

$ yarn add -D postcss-px-to-upx

Usage

Default Options:

{
  unitToConvert: 'DP',
  viewportWidth: 414,
  viewportHeight: 750,
  unitPrecision: 5,
  propList: ['*'],
  viewportUnit: 'rpx',
  fontViewportUnit: 'rpx',
  selectorBlackList: [],
  exclude: undefined,
  include: undefined
}
  • unitToConvert (String) unit to convert, by default, it is DP.
  • 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.
    • Values need to be exact matches.
    • Use wildcard * to enable all properties. Example: ['*']
    • Use * at the start or end of a word. (['position'] will match background-position-y)
    • Use ! to not match a property. Example: ['*', '!letter-spacing']
    • Combine the "not" prefix with the other prefixes. Example: ['', '!font']
  • viewportUnit (String) Expected units.
  • fontViewportUnit (String) Expected units for font.
  • selectorBlackList (Array) The selectors to ignore and leave as px.
    • If value is string, it checks to see if selector contains the string.
      • ['body'] will match .body-class
    • If value is regexp, it checks to see if the selector matches the regexp.
      • [/^body$/] will match body but not .body
  • exclude (Regexp or Array of Regexp) Ignore some files like 'node_modules'
    • If value is regexp, will ignore the matches files.
    • If value is array, the elements of the array are regexp.
  • 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\//)
    • If the value is regexp, the matching file will be included, otherwise it will be excluded.
    • If value is array, the elements of the array are regexp.

exclude and include can be set together, and the intersection of the two rules will be taken.

Use with PostCss configuration file

add to your postcss.config.js

module.exports = {
  plugins: {
    // ...
    'postcss-px-to-upx': {
      // options
    }
  }
}

Use with gulp-postcss

add to your gulpfile.js:

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var pxtoviewport = require('postcss-px-to-upx');

gulp.task('css', function () {

    var processors = [
        pxtoviewport({
            viewportWidth: 414,
            viewportUnit: 'rpx'
        })
    ];

    return gulp.src(['build/css/**/*.css'])
        .pipe(postcss(processors))
        .pipe(gulp.dest('build/css'));
});

Keywords

css

FAQs

Package last updated on 12 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.