{"id":20418475,"url":"https://github.com/yingye/postcss-px2units","last_synced_at":"2025-08-21T20:33:37.945Z","repository":{"id":41067058,"uuid":"124016243","full_name":"yingye/postcss-px2units","owner":"yingye","description":"A plugin for that generates rpx units from pixel units, it also can generate units which you want.","archived":false,"fork":false,"pushed_at":"2023-04-23T17:34:26.000Z","size":376,"stargazers_count":67,"open_issues_count":7,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-02T16:06:38.699Z","etag":null,"topics":["postcss-plugin","px2rpx","pxtorpx","rpx","wechat-mini-program"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/yingye.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-03-06T03:39:58.000Z","updated_at":"2024-06-18T18:31:36.215Z","dependencies_parsed_at":"2024-06-18T18:31:27.761Z","dependency_job_id":"b1c178c2-c8b6-45de-a3a3-dab71bf7b244","html_url":"https://github.com/yingye/postcss-px2units","commit_stats":{"total_commits":24,"total_committers":3,"mean_commits":8.0,"dds":0.08333333333333337,"last_synced_commit":"aa8bd31891b68d00961b6cbd0966d1326cbb58fa"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fpostcss-px2units","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fpostcss-px2units/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fpostcss-px2units/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fpostcss-px2units/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yingye","download_url":"https://codeload.github.com/yingye/postcss-px2units/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230532451,"owners_count":18240792,"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":["postcss-plugin","px2rpx","pxtorpx","rpx","wechat-mini-program"],"created_at":"2024-11-15T06:33:03.992Z","updated_at":"2024-12-20T04:08:25.128Z","avatar_url":"https://github.com/yingye.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"English | [简体中文](./README_CN.md)\n\n# postcss-px2units\n\n[![Build Status](https://travis-ci.org/yingye/postcss-px2units.svg?branch=master)](https://travis-ci.org/yingye/postcss-px2units)\n[![npm version](https://badge.fury.io/js/postcss-px2units.svg)](https://badge.fury.io/js/postcss-px2units)\n[![change-log](https://img.shields.io/badge/changelog-md-blue.svg)](https://github.com/yingye/postcss-px2units/blob/master/CHANGELOG.md)\n\nA plugin for [PostCSS](https://github.com/ai/postcss) that generates rpx units from pixel units, it also can generate units which you want.\n\n## Install\n\n```\n$ npm install postcss-px2units --save-dev\n```\n\n## Usage\n\n### Input/Output\n\nWith the default settings, we will get this output.\n\n```css\n/* input */\np {\n  margin: 0 0 20px;\n  font-size: 32px;\n  line-height: 1.2;\n  letter-spacing: 1px; /* no */\n}\n\n/* output */\np {\n  margin: 0 0 20rpx;\n  font-size: 32rpx;\n  line-height: 1.2;\n  letter-spacing: 1px;\n}\n```\n\n### Example\n\n```js\nvar fs = require('fs');\nvar postcss = require('postcss');\nvar pxtorem = require('postcss-pxtorem');\nvar css = fs.readFileSync('main.css', 'utf8');\nvar options = {\n    replace: false\n};\nvar processedCss = postcss(pxtorem(options)).process(css).css;\n\nfs.writeFile('main-rem.css', processedCss, function (err) {\n  if (err) {\n    throw err;\n  }\n  console.log('Rem file written.');\n});\n```\n\n### options\n\nType: Object | Null\n\nDefault:\n\n```js\n{\n  divisor: 1,\n  multiple: 1,\n  decimalPlaces: 2,\n  comment: 'no',\n  targetUnits: 'rpx'\n}\n```\n\nDetail:\n\n- divisor(Number): divisor, replace pixel value with pixel / divisor.\n- multiple(Number): multiple, replace pixel value with pixel * multiple.\n- decimalPlaces(Number): the number of decimal places. For example, the css code is `width: 100px`, we will get the vaule is `Number(100 / divisor * multiple).toFixed(decimalPlaces)`.\n- comment(String): default value is 'no'. For example, if you set it 'not replace', the css code `width: 100px; /* not replace */` will be translated to `width: 100px;`\n- targetUnits(String): The units will replace pixel units, you can set it 'rem'.\n\n### Use with gulp-postcss\n\n```js\nvar gulp = require('gulp');\nvar postcss = require('gulp-postcss');\nvar pxtounits = require('postcss-pxtounits');\n\ngulp.task('css', function () {\n  return gulp.src('./test/src/css/**/*.css')\n    .pipe(postcss([pxtounits()]))\n    .pipe(gulp.dest('./test/dist/css'));\n});\n```\n\n## Tips\n\nIf you want to use it in WePY, please use [wepy-plugin-px2units](https://github.com/yingye/wepy-plugin-px2units).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingye%2Fpostcss-px2units","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyingye%2Fpostcss-px2units","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingye%2Fpostcss-px2units/lists"}