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 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-rpx-plugin

v2.0.1

Published

postcss rpx plugin rpx2vw

Downloads

39

Readme

postcss-rpx-plugin

Version npm GitHub package.json version GitHub

中文 README

Based on postcss A plug-in for converting rpx units in CSS into VW units. It is applicable to the design draft with fixed width and uncertain height in the mobile end. You can also set the width and matching unit by yourself.

/* before */
.rule {
  margin: 10rpx 375rpx 0rpx 10px;
  height: 375rpx;
  background: url(icon-16rpx.jpg);
}

/* after */
.rule {
  margin: 1.33333vw 50vw 0 10px;
  height: 50vw;
  background: url(icon-16rpx.jpg);
}

Usage

First install postcss-loader And postcss。 CLI with CSS loader integrated can skip this step

npm i postcss postcss-loader -D

Install the plug-in

npm i postcss-rpx-plugin -D

Please use the version of postcss@7 postcss@6 postcss@5

# postcss@7 postcss@6 postcss@5
npm i [email protected] -D

configure

in postcss.config.js

module.exports = {
  plugins: [
    // register
    require("postcss-rpx-plugin"),
  ],
};

custom configure postcss.config.js

module.exports = {
  plugins: [
    [
      "postcss-rpx-plugin",
      {
        unit: "rpx",
        width: 750,
        precision: 5,
        outUnit: "vw",
        exclude: "",
      },
    ],
  ],
};

or in package.json

{
  "dependencies": {},
  "devDependencies": {},
  "postcss": {
    "plugins": {
      "postcss-rpx-plugin": {
        "unit": "rpx",
        "width": 750,
        "precision": 5,
        "outUnit": "vw",
        "exclude": ""
      }
    }
  }
}

Options

const unit = options?.unit || "rpx"; // unit
const width = options?.width || 750; // ui design width
const precision = options?.precision || 5; // decimal places
const outUnit = options?.outUnit || "vw"; //  out unit
const exclude = options?.exclude || ""; // exclude some file,support regex

CHANGELOG

V2.0.1

  • fix readme
  • add test
    it("should exclude file", () => {
      const rules = ".rule { margin: 10rpx 375rpx 0rpx 10px; }";
      const expected = ".rule { margin: 10rpx 375rpx 0rpx 10px; }";
      const from = "c:/a/b/c/d.css";
      const pc = postcss(rpx2vm({ exclude: ".css" }));
      const processed = pc.process(rules, { from }).css;
      expect(processed).toBe(expected);
    });

V2.0.0

  • support postcss@8

V1.0.3

  • fix build options?.unit error
  • fix @type ?

V1.0.2

  • add @type

V1.0.1

  • Float rpx

    it("should replace the rpx unit with vw - Float", () => {
      const rules = ".rule { height: 375.0rpx; }";
      const expected = ".rule { height: 50vw; }";
      const processed = postcss(rpx2vm()).process(rules).css;
      expect(processed).toBe(expected);
    });
  • url ignore

    it("should not replace values in `url()`", () => {
      const rules = ".rule { background: url(icon-16rpx.jpg); }";
      const expected = ".rule { background: url(icon-16rpx.jpg); }";
      const processed = postcss(rpx2vm()).process(rules).css;
      expect(processed).toBe(expected);
    });

V1.0.0

  • Int rpx
    it("should replace the rpx unit with vw - Int", () => {
      const rules = ".rule { margin: 10rpx 375rpx 0rpx 10px; }";
      const expected = ".rule { margin: 1.33333vw 50vw 0 10px; }";
      const processed = postcss(rpx2vm()).process(rules).css;
      expect(processed).toBe(expected);
    });

Thanks

postcss-rpxtopx

postcss-rpx-loader

Other

GitHub

You are welcome to put forward your ideas and feedback issues