{"id":16039985,"url":"https://github.com/sonofmagic/postcss-rpx-transform","last_synced_at":"2025-06-30T10:32:22.673Z","repository":{"id":54969873,"uuid":"522389650","full_name":"sonofmagic/postcss-rpx-transform","owner":"sonofmagic","description":"postcss-rpx-transform","archived":false,"fork":false,"pushed_at":"2023-12-15T20:13:11.000Z","size":103,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-12T07:56:24.504Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sonofmagic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-08T03:15:48.000Z","updated_at":"2025-03-25T04:43:16.000Z","dependencies_parsed_at":"2023-12-15T21:41:35.979Z","dependency_job_id":"2261bba5-8e56-4f24-9326-377b9cc992ae","html_url":"https://github.com/sonofmagic/postcss-rpx-transform","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"8e8326ed8b3d8e301099c85294ed47c26d17be12"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"sonofmagic/npm-lib-template","purl":"pkg:github/sonofmagic/postcss-rpx-transform","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonofmagic%2Fpostcss-rpx-transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonofmagic%2Fpostcss-rpx-transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonofmagic%2Fpostcss-rpx-transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonofmagic%2Fpostcss-rpx-transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonofmagic","download_url":"https://codeload.github.com/sonofmagic/postcss-rpx-transform/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonofmagic%2Fpostcss-rpx-transform/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259519862,"owners_count":22870371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T23:09:20.443Z","updated_at":"2025-06-30T10:32:22.595Z","avatar_url":"https://github.com/sonofmagic.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postcss-rpx-transform\n\n- [postcss-rpx-transform](#postcss-rpx-transform)\n  - [何时使用？](#何时使用)\n  - [如何使用](#如何使用)\n    - [Postcss8](#postcss8)\n    - [Postcss7](#postcss7)\n  - [配置项](#配置项)\n\n\u003e `Let's make rpx great again!` LOL\n\n`postcss-pxtransform` 的反向版本，用来把小程序的 `rpx` 单位，转化为 `px`，`rem`，`vw` 这些单位。\n\n## 何时使用？\n\n有些项目，是以小程序为主体进行设计的，一开始可能只要求做一个小程序，但是后续逐渐产生了`app`和`h5`这些其他平台的需求。\n\n此时由于开发者们样式里，全部用了`rpx`这类的单位，`h5`压根不认识这个单位，而此时全局更改`rpx`到其他单位(`px`,`rem`)的成本也比较高，此时你就需要这个插件来进行反向转化！\n\n## 如何使用\n\n### Postcss8\n\n```js\n// postcss.config.js\nmodule.exports = {\n  plugins: [\n    require('postcss-rpx-transform')(),\n  ],\n}\n```\n\n### Postcss7\n\n```js\n// postcss.config.js\nmodule.exports = {\n  plugins: [\n    require('postcss-rpx-transform/postcss7')(),\n  ],\n}\n```\n\n## 配置项\n\n```ts\nexport interface UserDefinedOptions {\n  // 反向转化的基准单位，默认是32，即 32rpx = 16px = 1rem = 32/750 * 100vw\n  rootValue?: number | ((input: Input) =\u003e number)\n  // 四舍五入后保留小数\n  unitPrecision?: number\n  // 选择器黑名单，会直接跳过黑名单内的处理\n  selectorBlackList?: (string | RegExp)[]\n  // 处理的 css 属性列表\n  propList?: string[]\n  // 处理策略为直接覆盖原先 replace，还是添加覆盖 appned\n  replace?: boolean\n  // 是否处理媒体查询\n  mediaQuery?: boolean\n  // 最小值以下不处理\n  minValue?: number\n  // 排除指定路径不处理\n  exclude?: string | RegExp | ((filePath: string) =\u003e boolean)\n  // 转化的目标单位，支持 rpx2px,rpx2rem,rpx2vw\n  transformUnit?: 'px' | 'rem' | 'vw'\n}\n// 默认值\nexport const defaultOptions: Required\u003cUserDefinedOptions\u003e = {\n  // 32rpx = 16px = 1rem = 32/750 * 100vw\n  rootValue: 32,\n  unitPrecision: 5,\n  selectorBlackList: [],\n  propList: ['*'],\n  replace: true,\n  mediaQuery: false,\n  minValue: 0,\n  exclude: /node_modules/i,\n  transformUnit: 'px'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonofmagic%2Fpostcss-rpx-transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonofmagic%2Fpostcss-rpx-transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonofmagic%2Fpostcss-rpx-transform/lists"}