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

babel-plugin-px2dp

v1.0.6

Published

convenient to handle rn style

Readme

babel-plugin-px2dp

babel的样式单位处理插件,用于react-native开发者进行样式转换使用


Why babel-plugin-px2dp

  • 对于rn的开发来说,样式单位转换是一个小痛点。
  • 类似于px2rem / px2vw等插件使我们在进行web开发的时候更为高效,本插件就是帮助rn开发者进行dp单位转换所使用的

Where to add babel-plugin-import

Example

["px2dp", { "uiWidth": 750 }]

Result

ps.请注意必须在你要转换的文件头部加上px2dp的标识用于插件检测,否则无法进行转换!

最基础的转换

'px2dp';
...

StyleSheet.create({
    example: {
        width: '20px',
    }
})

      ↓ ↓ ↓ ↓ ↓ ↓

...
import { Dimensions } from 'react-native';

StyleSheet.create({
    example: {
        width: ds.get('window').width * 20 / 750, // 750是你设置的uiWidth的值
    }
})

如果原始文件已经引用过Dimensions,则不去新增引用


'px2dp';
...
import { Dimensions, xxx } from 'react-native';

StyleSheet.create({
    example: {
        width: '20px',
        height: Dimensions.get('window').height,
    }
})

      ↓ ↓ ↓ ↓ ↓ ↓

...
import { Dimensions, xxx } from 'react-native';

StyleSheet.create({
    example: {
        width: Dimensions.get('window').width * 20 / 750,
        height: Dimensions.get('window').height,
    }
})

如果原始文件已经引用过Dimensions并且设置了别名,插件会按照别名进行处理

'px2dp';
...
import { ds as Dimensions, xxx } from 'react-native';

StyleSheet.create({
    example: {
        width: '20px',
        height: ds.get('window').height,
    }
})

      ↓ ↓ ↓ ↓ ↓ ↓

...
import { ds as Dimensions, xxx } from 'react-native';

StyleSheet.create({
    example: {
        width: ds.get('window').width * 20 / 750,
        height: ds.get('window').height,
    }
})

如果原始文件并未引用过Dimensions,插件会去融合之前的引用


'px2dp';
...
import { xxx } from 'react-native';

StyleSheet.create({
    example: {
        width: '20px',
    }
})

      ↓ ↓ ↓ ↓ ↓ ↓

...
import { Dimensions, xxx } from 'react-native';

StyleSheet.create({
    example: {
        width: Dimensions.get('window').width * 20 / 750,
    }
})

Usage

npm install babel-plugin-px2dp --save-dev

Via .babelrc

{
  "plugins": [["px2dp", options]]
}

options

options can be object.

{
  "uiWidth": 750, // ui设计稿宽度
}