{"id":13433928,"url":"https://github.com/postcss/postcss-nested","last_synced_at":"2025-05-11T05:46:15.782Z","repository":{"id":22991996,"uuid":"26342454","full_name":"postcss/postcss-nested","owner":"postcss","description":"PostCSS plugin to unwrap nested rules like how Sass does it.","archived":false,"fork":false,"pushed_at":"2024-12-17T07:09:01.000Z","size":855,"stargazers_count":1183,"open_issues_count":5,"forks_count":66,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-11T05:46:10.324Z","etag":null,"topics":[],"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/postcss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"open_collective":"postcss","github":"ai"}},"created_at":"2014-11-07T23:14:54.000Z","updated_at":"2025-05-09T06:37:16.000Z","dependencies_parsed_at":"2023-09-21T19:19:47.357Z","dependency_job_id":"38365e21-b053-4400-a337-77a9d85a550c","html_url":"https://github.com/postcss/postcss-nested","commit_stats":{"total_commits":242,"total_committers":31,"mean_commits":7.806451612903226,"dds":0.2024793388429752,"last_synced_commit":"32a57d0a675e40a43a4734888bbafdfaada00610"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-nested","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-nested/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-nested/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-nested/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postcss","download_url":"https://codeload.github.com/postcss/postcss-nested/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523719,"owners_count":21921818,"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-07-31T02:01:40.600Z","updated_at":"2025-05-11T05:46:15.752Z","avatar_url":"https://github.com/postcss.png","language":"JavaScript","readme":"# PostCSS Nested\n\n\u003cimg align=\"right\" width=\"135\" height=\"95\"\n     title=\"Philosopher’s stone, logo of PostCSS\"\n     src=\"https://postcss.org/logo-leftp.svg\"\u003e\n\n[PostCSS] plugin to unwrap nested rules closer to Sass syntax.\n\n```css\n.phone {\n  \u0026_title {\n    width: 500px;\n    @media (max-width: 500px) {\n      width: auto;\n    }\n    body.is_dark \u0026 {\n      color: white;\n    }\n  }\n  img {\n    display: block;\n  }\n}\n\n.title {\n  font-size: var(--font);\n\n  @at-root html {\n    --font: 16px;\n  }\n}\n```\n\nwill be processed to:\n\n```css\n.phone_title {\n  width: 500px;\n}\n@media (max-width: 500px) {\n  .phone_title {\n    width: auto;\n  }\n}\nbody.is_dark .phone_title {\n  color: white;\n}\n.phone img {\n  display: block;\n}\n\n.title {\n  font-size: var(--font);\n}\nhtml {\n  --font: 16px;\n}\n```\n\nRelated plugins:\n\n- Use [`postcss-current-selector`] **after** this plugin if you want\n  to use current selector in properties or variables values.\n- Use [`postcss-nested-ancestors`] **before** this plugin if you want\n  to reference any ancestor element directly in your selectors with `^\u0026`.\n\nAlternatives:\n\n- See also [`postcss-nesting`], which implements [CSSWG draft].\n- [`postcss-nested-props`] for nested properties like `font-size`.\n\n\u003ca href=\"https://evilmartians.com/?utm_source=postcss-nested\"\u003e\n  \u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\"\n       alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\n\u003c/a\u003e\n\n[`postcss-current-selector`]: https://github.com/komlev/postcss-current-selector\n[`postcss-nested-ancestors`]: https://github.com/toomuchdesign/postcss-nested-ancestors\n[`postcss-nested-props`]: https://github.com/jedmao/postcss-nested-props\n[`postcss-nesting`]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting\n[CSSWG draft]: https://drafts.csswg.org/css-nesting-1/\n[PostCSS]: https://github.com/postcss/postcss\n\n## Usage\n\n**Step 1:** Install plugin:\n\n```sh\nnpm install --save-dev postcss postcss-nested\n```\n\n**Step 2:** Check your project for existing PostCSS config: `postcss.config.js`\nin the project root, `\"postcss\"` section in `package.json`\nor `postcss` in bundle config.\n\nIf you do not use PostCSS, add it according to [official docs]\nand set this plugin in settings.\n\n**Step 3:** Add the plugin to plugins list:\n\n```diff\nmodule.exports = {\n  plugins: [\n+   require('postcss-nested'),\n    require('autoprefixer')\n  ]\n}\n```\n\n[official docs]: https://github.com/postcss/postcss#usage\n\n## Options\n\n### `bubble`\n\nBy default, plugin will bubble only `@media`, `@supports`, `@layer`,\n`@container`, and `@starting-style` at-rules. Use this option\nto add your custom at-rules to this list.\n\n```js\npostcss([require('postcss-nested')({ bubble: ['phone'] })])\n```\n\n```css\n/* input */\na {\n  color: white;\n  @phone {\n    color: black;\n  }\n}\n/* output */\na {\n  color: white;\n}\n@phone {\n  a {\n    color: black;\n  }\n}\n```\n\n### `unwrap`\n\nBy default, plugin will unwrap only `@font-face`, `@keyframes` and `@document`\nat-rules. You can add your custom at-rules to this list by `unwrap` option:\n\n```js\npostcss([require('postcss-nested')({ unwrap: ['phone'] })])\n```\n\n```css\n/* input */\na {\n  color: white;\n  @phone {\n    color: black;\n  }\n}\n/* output */\na {\n  color: white;\n}\n@phone {\n  color: black;\n}\n```\n\n### `preserveEmpty`\n\nBy default, plugin will strip out any empty selector generated by intermediate\nnesting levels. You can set `preserveEmpty` to `true` to preserve them.\n\n```css\n.a {\n  .b {\n    color: black;\n  }\n}\n```\n\nWill be compiled to:\n\n```css\n.a {\n}\n.a .b {\n  color: black;\n}\n```\n\nThis is especially useful if you want to export the empty classes with `postcss-modules`.\n\n### `rootRuleName`\n\nThe plugin supports the SCSS custom at-rule `@at-root` which breaks rule\nblocks out of their nested position. If you want, you can choose a new\ncustom name for this rule in your code.\n\n```js\npostcss([require('postcss-nested')({ rootRuleName: '_escape-nesting' })])\n```\n\n```css\n/* input */\n.a {\n  color: white;\n  @_escape-nesting {\n    .b {\n      color: black;\n    }\n  }\n}\n/* output */\n.a {\n  color: white;\n}\n.b {\n  color: black;\n}\n```\n","funding_links":["https://opencollective.com/postcss","https://github.com/sponsors/ai"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostcss%2Fpostcss-nested","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostcss%2Fpostcss-nested","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostcss%2Fpostcss-nested/lists"}