{"id":13459117,"url":"https://github.com/evrone/postcss-px-to-viewport","last_synced_at":"2025-05-14T02:04:52.027Z","repository":{"id":37451307,"uuid":"49870609","full_name":"evrone/postcss-px-to-viewport","owner":"evrone","description":"A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units. The best choice to create a scalable interface on different displays by one design size.","archived":false,"fork":false,"pushed_at":"2024-06-18T10:27:27.000Z","size":277,"stargazers_count":3137,"open_issues_count":108,"forks_count":410,"subscribers_count":54,"default_branch":"master","last_synced_at":"2025-05-11T12:51:20.576Z","etag":null,"topics":["css-scale","media-queries","mobile-design","pixel-units","postcss","rem-units","taro","vh","viewport-units","vw"],"latest_commit_sha":null,"homepage":"https://evrone.com/postcss-px-viewport","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/evrone.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","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":"2016-01-18T10:50:01.000Z","updated_at":"2025-05-09T01:22:43.000Z","dependencies_parsed_at":"2024-06-18T11:28:39.916Z","dependency_job_id":null,"html_url":"https://github.com/evrone/postcss-px-to-viewport","commit_stats":{"total_commits":53,"total_committers":10,"mean_commits":5.3,"dds":0.4339622641509434,"last_synced_commit":"9d6c5cee5eea367fb4c7cf0c3bb1117979b5fbf4"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evrone%2Fpostcss-px-to-viewport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evrone%2Fpostcss-px-to-viewport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evrone%2Fpostcss-px-to-viewport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evrone%2Fpostcss-px-to-viewport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evrone","download_url":"https://codeload.github.com/evrone/postcss-px-to-viewport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253568678,"owners_count":21928908,"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":["css-scale","media-queries","mobile-design","pixel-units","postcss","rem-units","taro","vh","viewport-units","vw"],"created_at":"2024-07-31T09:01:04.914Z","updated_at":"2025-05-14T02:04:51.952Z","avatar_url":"https://github.com/evrone.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# postcss-px-to-viewport\n[![NPM version](https://badge.fury.io/js/postcss-px-to-viewport.svg)](http://badge.fury.io/js/postcss-px-to-viewport)\n\nEnglish | [中文](README_CN.md) \n\nA plugin for [PostCSS](https://github.com/postcss/postcss) that generates viewport units (vw, vh, vmin, vmax) from pixel units.\n\n## Demo\n\nIf your project involves a fixed width, this script will help to convert pixels into viewport units.\n\n### Input\n\n```css\n.class {\n  margin: -10px .5vh;\n  padding: 5vmin 9.5px 1px;\n  border: 3px solid black;\n  border-bottom-width: 1px;\n  font-size: 14px;\n  line-height: 20px;\n}\n\n.class2 {\n  padding-top: 10px; /* px-to-viewport-ignore */\n  /* px-to-viewport-ignore-next */\n  padding-bottom: 10px;\n  /* Any other comment */\n  border: 1px solid black;\n  margin-bottom: 1px;\n  font-size: 20px;\n  line-height: 30px;\n}\n\n@media (min-width: 750px) {\n  .class3 {\n    font-size: 16px;\n    line-height: 22px;\n  }\n}\n```\n\n### Output\n```css\n.class {\n  margin: -3.125vw .5vh;\n  padding: 5vmin 2.96875vw 1px;\n  border: 0.9375vw solid black;\n  border-bottom-width: 1px;\n  font-size: 4.375vw;\n  line-height: 6.25vw;\n}\n\n.class2 {\n  padding-top: 10px;\n  padding-bottom: 10px;\n  /* Any other comment */\n  border: 1px solid black;\n  margin-bottom: 1px;\n  font-size: 6.25vw;\n  line-height: 9.375vw;\n}\n\n@media (min-width: 750px) {\n  .class3 {\n    font-size: 16px;\n    line-height: 22px;\n  }\n}\n```\n\n## Getting Started\n\n### Installation\nAdd via npm\n```\n$ npm install postcss-px-to-viewport --save-dev\n```\nor yarn\n```\n$ yarn add -D postcss-px-to-viewport\n```\n\n### Usage\n\nDefault Options:\n```js\n{\n  unitToConvert: 'px',\n  viewportWidth: 320,\n  unitPrecision: 5,\n  propList: ['*'],\n  viewportUnit: 'vw',\n  fontViewportUnit: 'vw',\n  selectorBlackList: [],\n  minPixelValue: 1,\n  mediaQuery: false,\n  replace: true,\n  exclude: undefined,\n  include: undefined,\n  landscape: false,\n  landscapeUnit: 'vw',\n  landscapeWidth: 568\n}\n```\n- `unitToConvert` (String) unit to convert, by default, it is px.\n- `viewportWidth` (Number) The width of the viewport.\n- `unitPrecision` (Number) The decimal numbers to allow the vw units to grow to.\n- `propList` (Array) The properties that can change from px to vw.\n  - Values need to be exact matches.\n  - Use wildcard * to enable all properties. Example: ['*']\n  - Use * at the start or end of a word. (['*position*'] will match background-position-y)\n  - Use ! to not match a property. Example: ['*', '!letter-spacing']\n  - Combine the \"not\" prefix with the other prefixes. Example: ['*', '!font*']\n- `viewportUnit` (String) Expected units.\n- `fontViewportUnit` (String) Expected units for font.\n- `selectorBlackList` (Array) The selectors to ignore and leave as px.\n    - If value is string, it checks to see if selector contains the string.\n        - `['body']` will match `.body-class`\n    - If value is regexp, it checks to see if the selector matches the regexp.\n        - `[/^body$/]` will match `body` but not `.body`\n- `minPixelValue` (Number) Set the minimum pixel value to replace.\n- `mediaQuery` (Boolean) Allow px to be converted in media queries.\n- `replace` (Boolean) replaces rules containing vw instead of adding fallbacks.\n- `exclude` (Regexp or Array of Regexp) Ignore some files like 'node_modules'\n    - If value is regexp, will ignore the matches files.\n    - If value is array, the elements of the array are regexp.\n- `include` (Regexp or Array of Regexp) If `include` is set, only matching files will be converted,\n    for example, only files under `src/mobile/` (`include: /\\/src\\/mobile\\//`)\n    - If the value is regexp, the matching file will be included, otherwise it will be excluded.\n    - If value is array, the elements of the array are regexp.\n- `landscape` (Boolean) Adds `@media (orientation: landscape)` with values converted via `landscapeWidth`.\n- `landscapeUnit` (String) Expected unit for `landscape` option\n- `landscapeWidth` (Number) Viewport width for landscape orientation.\n\n\u003e `exclude` and `include` can be set together, and the intersection of the two rules will be taken.\n\n#### Ignoring\n\nYou can use special comments for ignore conversion of single lines:\n- `/* px-to-viewport-ignore-next */` — on a separate line, prevents conversion on the next line.\n- `/* px-to-viewport-ignore */` — after the property on the right, prevents conversion on the same line.\n\nExample:\n```css\n/* example input: */\n.class {\n  /* px-to-viewport-ignore-next */\n  width: 10px;\n  padding: 10px;\n  height: 10px; /* px-to-viewport-ignore */\n  border: solid 2px #000; /* px-to-viewport-ignore */\n}\n\n/* example output: */\n.class {\n  width: 10px;\n  padding: 3.125vw;\n  height: 10px;\n  border: solid 2px #000;\n}\n```\n\nThere are several more reasons why your pixels may not convert, the following options may affect this:\n`propList`, `selectorBlackList`, `minPixelValue`, `mediaQuery`, `exclude`, `include`.\n\n#### Use with PostCss configuration file\n\nadd to your `postcss.config.js`\n```js\nmodule.exports = {\n  plugins: {\n    // ...\n    'postcss-px-to-viewport': {\n      // options\n    }\n  }\n}\n```\n\n#### Use with gulp-postcss\n\nadd to your `gulpfile.js`:\n```js\nvar gulp = require('gulp');\nvar postcss = require('gulp-postcss');\nvar pxtoviewport = require('postcss-px-to-viewport');\n\ngulp.task('css', function () {\n\n    var processors = [\n        pxtoviewport({\n            viewportWidth: 320,\n            viewportUnit: 'vmin'\n        })\n    ];\n\n    return gulp.src(['build/css/**/*.css'])\n        .pipe(postcss(processors))\n        .pipe(gulp.dest('build/css'));\n});\n```\n\n## Contributing\n\nPlease read [Code of Conduct](CODE-OF-CONDUCT.md)\nand [Contributing Guidelines](CONTRIBUTING.md) for submitting pull requests to us.\n\n## Running the tests\n\nIn order to run tests, you need to install dev-packages:\n```\n$ npm install\n```\nThen run the tests via npm script:\n```\n$ npm run test\n```\n\n## Changelog\n\nThe changelog is [here](CHANGELOG.md).\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/evrone/postcss-px-to-viewport/tags). \n\n## Authors\n\n* [Dmitry Karpunin](https://github.com/KODerFunk) - *Initial work*\n* [Ivan Bunin](https://github.com/chernobelenkiy)\n\nSee also the list of [contributors](https://github.com/evrone/postcss-px-to-viewport/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## Sponsors\n\nVisit [Evrone](https://evrone.com/) website to get more information about the [projects](https://evrone.com/cases) build.\n\n\u003ca href=\"https://evrone.com/?utm_source=postcss-px-to-viewport\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/417688/34437029-dbfe4ee6-ecab-11e7-9d80-2b274b4149b3.png\"\n       alt=\"Sponsored by Evrone\" width=\"231\" /\u003e\n\u003c/a\u003e\n\n## Acknowledgments\n\n* Hat tip to https://github.com/cuth/postcss-pxtorem/ for inspiring us for this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevrone%2Fpostcss-px-to-viewport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevrone%2Fpostcss-px-to-viewport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevrone%2Fpostcss-px-to-viewport/lists"}