npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

postcss-rpx-to-viewport

v0.0.1

Published

a plugin for PostCSS, convert rpx units (h5/mini-program/mpvue) to viewport units (vw or vmin vmax vh)

Readme

rpx-to-viewport

A plugin for PostCSS. Convert rpx units (h5/mini-program/mpvue) to viewport units (vw or vmin vmax vh)

purpose

  1. for h5、mini-program、mpvue and so on
  2. write css unit the same as your layout (Example: 750px width layout = 750rpx)

Usage

npm install postcss-rpx-to-viewport --save-dev

Use with gulp

var gulp = require('gulp');
var postCss = require('gulp-postcss');
var rpxToViewport = require('postcss-rpx-to-viewport');

gulp.task('css', function () {
    var processors = [
        rpxToViewport()   // layoutWidth default 750, if you layout is 640, use as rpxToViewport({layoutWidth: 640}) 
    ];
    return gulp.src(['build/css/**/*.css'])
        .pipe(postCss(processors))
        .pipe(gulp.dest('build/css'));
});

Use with webpack & vue

    var rpxToViewport = require('postcss-rpx-to-viewport');
    
    // webpack config: 
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: [
                    {
                        loader: 'vue-loader',
                        options: {
                            postcss: [
                                rpxToViewport()
                            ],
                        }
                    }
                ],

            }
        ]
    }    

Use with webpack & react

    var rpxToViewport = require('postcss-rpx-to-viewport');

    // webpack config: 
    module: {
      postcss: function () {
          return [rpxToViewport()];
      },
    }    

Example


/* input : Suppose your layout width is 750px */

.foo {
  width: 750rpx;
  height: 150rpx;
  margin: 10rpx;
  padding: 1rpx 15rpx 1px 30rpx; /* 1rpx will be converted any way */
  border: 4rpx solid gray;
  font-size: 15rpx;
  line-height: 14rpx;
}

.bar {
  width: 100px;
  margin: 10px;
  padding: 2px 15px 1px 16px;
  border: 1px solid gray;
  font-size: 14px;  /* px will not be converted */
  line-height: 14px;
}

@media (min-width: 750rpx) {  /* suggest use px */
  .foo {
    font-size: 16rpx;
    line-height: 15rpx;
  }
}


/* output */

.foo {
  width: 100vw;
  height: 20vw;
  margin: 1.33333vw;
  padding: 0.13333vw 2vw 1px 4vw; 
  border: 0.53333vw solid gray;
  font-size: 2vw;
  line-height: 1.86667vw;
}

.bar {
  width: 100px;
  margin: 10px;
  padding: 2px 15px 1px 16px;
  border: 1px solid gray;
  font-size: 14px;  
  line-height: 14px;
}

@media (min-width: 100vw) {  /* if use rpx and set mediaQuery===true */
  .foo {
    font-size: 2.13333vw;
    line-height: 2vw;
  }
}

Options

Default:

{
  targetUnit: 'rpx',    // (String) need convert
  outputUnit: 'vw',     // (String) convert to
  layoutWidth: 750,     // (Number) design draft width
  unitPrecision: 5,     // (Number) the decimal numbers
  mediaQuery: false     // (Boolean) convert the unit inside @media(*)
}

Changelog

0.0.1 (November 21st 2018)

License

MIT License.