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-transform

v1.0.1

Published

Let's make rpx great again! convert rpx (responsive-pixel) to px,rem,vw

Downloads

14

Readme

postcss-rpx-transform

Let's make rpx great again! LOL

postcss-pxtransform 的反向版本,用来把小程序的 rpx 单位,转化为 pxremvw 这些单位。

何时使用?

有些项目,是以小程序为主体进行设计的,一开始可能只要求做一个小程序,但是后续逐渐产生了apph5这些其他平台的需求。

此时由于开发者们样式里,全部用了rpx这类的单位,h5压根不认识这个单位,而此时全局更改rpx到其他单位(px,rem)的成本也比较高,此时你就需要这个插件来进行反向转化!

如何使用

Postcss8

// postcss.config.js
module.exports = {
  plugins: [
    require('postcss-rpx-transform')(),
  ],
}

Postcss7

// postcss.config.js
module.exports = {
  plugins: [
    require('postcss-rpx-transform/postcss7')(),
  ],
}

配置项

export interface UserDefinedOptions {
  // 反向转化的基准单位,默认是32,即 32rpx = 16px = 1rem = 32/750 * 100vw
  rootValue?: number | ((input: Input) => number)
  // 四舍五入后保留小数
  unitPrecision?: number
  // 选择器黑名单,会直接跳过黑名单内的处理
  selectorBlackList?: (string | RegExp)[]
  // 处理的 css 属性列表
  propList?: string[]
  // 处理策略为直接覆盖原先 replace,还是添加覆盖 appned
  replace?: boolean
  // 是否处理媒体查询
  mediaQuery?: boolean
  // 最小值以下不处理
  minValue?: number
  // 排除指定路径不处理
  exclude?: string | RegExp | ((filePath: string) => boolean)
  // 转化的目标单位,支持 rpx2px,rpx2rem,rpx2vw
  transformUnit?: 'px' | 'rem' | 'vw'
}
// 默认值
export const defaultOptions: Required<UserDefinedOptions> = {
  // 32rpx = 16px = 1rem = 32/750 * 100vw
  rootValue: 32,
  unitPrecision: 5,
  selectorBlackList: [],
  propList: ['*'],
  replace: true,
  mediaQuery: false,
  minValue: 0,
  exclude: /node_modules/i,
  transformUnit: 'px'
}