{"id":20961663,"url":"https://github.com/elchininet/postcss-comments","last_synced_at":"2025-12-24T18:40:18.617Z","repository":{"id":189026346,"uuid":"679448976","full_name":"elchininet/postcss-comments","owner":"elchininet","description":"Postcss plugin to prepend or append comments to CSS rules","archived":false,"fork":false,"pushed_at":"2024-04-08T22:32:28.000Z","size":758,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-10T01:12:27.930Z","etag":null,"topics":["comments","css","postcss","postcss-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elchininet.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},"funding":{"github":"elchininet"}},"created_at":"2023-08-16T21:48:40.000Z","updated_at":"2024-04-15T00:29:06.582Z","dependencies_parsed_at":"2024-01-10T00:25:24.155Z","dependency_job_id":"6ed4ac37-3c08-4b43-ae1f-812d8af8d711","html_url":"https://github.com/elchininet/postcss-comments","commit_stats":null,"previous_names":["elchininet/postcss-comments"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fpostcss-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fpostcss-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fpostcss-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elchininet%2Fpostcss-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elchininet","download_url":"https://codeload.github.com/elchininet/postcss-comments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243358306,"owners_count":20277995,"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":["comments","css","postcss","postcss-plugin"],"created_at":"2024-11-19T02:15:11.843Z","updated_at":"2025-12-24T18:40:18.610Z","avatar_url":"https://github.com/elchininet.png","language":"TypeScript","funding_links":["https://github.com/sponsors/elchininet"],"categories":[],"sub_categories":[],"readme":"# PostCSS Comments\n[PostCSS] plugin to prepend and append comments to CSS rules.\n\n[![Deployment Status](https://github.com/elchininet/postcss-comments/actions/workflows/deploy.yaml/badge.svg)](https://github.com/elchininet/postcss-comments/actions/workflows/deploy.yaml)\n[![Tests](https://github.com/elchininet/postcss-comments/actions/workflows/test.yaml/badge.svg)](https://github.com/elchininet/postcss-comments/actions/workflows/test.yaml)\n[![Coverage Status](https://coveralls.io/repos/github/elchininet/postcss-comments/badge.svg?branch=master)](https://coveralls.io/github/elchininet/postcss-comments?branch=master)\n[![npm version](https://badge.fury.io/js/postcss-comments.svg)](https://badge.fury.io/js/postcss-comments)\n\nDescription\n---\n\nSome [PostCSS] plugins require to add comments to the CSS code to be able to perform their work (e.g. [RTLCSS] or [PostCSS RTLCSS]). But if the CSS code is coming from a third-party library or a CSS-in-JS framework it is impossible to modify the CSS source to add comments. In these cases, `postcss-comments` could be helpful to prepend or append comments to CSS rules selecting them using strings or regular expressions.\n\nInstall\n---\n\n#### npm\n\n```bash\nnpm install postcss-comments --save-dev\n```\n\n#### yarn\n\n```bash\nyarn add postcss-comments -D\n```\n\n#### Usage with commonJS\n\n```javascript\nconst postcss = require('postcss');\nconst postcssComments = require('postcss-comments');\n\nconst result = postcss([\n    postcssComments({\n        rulesMatchers: [\n            /* rulesMatchers */\n        ]\n    })\n]).process(cssInput);\n\nconst commentedCSS = result.css;\n```\n\n#### Usage with ES6 modules\n\n```javascript\nimport postcss from 'postcss';\nimport postcssComments from 'postcss-comments';\n\nconst result = postcss([\n    postcssComments({\n        rulesMatchers: [\n            /* rulesMatchers */\n        ]\n    })\n]).process(cssInput);\n\nconst commentedCSS = result.css;\n```\n\n#### Usage in Webpack with postcss-loader\n\n```javascript\nrules: [\n    {\n        test: /\\.css$/,\n        use: [\n            { loader: 'style-loader' },\n            { loader: 'css-loader' },\n            {\n                loader: 'postcss-loader',\n                options: {\n                    postcssOptions: {\n                        plugins: [\n                            postcssComments({\n                                rulesMatchers: [\n                                    /* rulesMatchers */\n                                ]\n                            })\n                        ]\n                    }\n                }\n            }\n        ]\n    }\n]\n```\n\nRules Matchers\n---\n\n`rulesMatchers` consist on an array of objects, each one describing one matcher.\n\n```javascript\n{\n    matcher: string | RegExp | (string | RegExp)[];\n    prepend?: string;\n    append?: string;\n}\n```\nExamples\n---\n\n#### Input\n\n```css\n.test1, .test2 {\n    color: #666;\n    padding-right: 20px;\n    width: 100%;\n}\n\n.link {\n    color: red;\n}\n\n.link:hover {\n    color: red;\n}\n\n.link:visited {\n    color: red;\n}\n\n.test-class {\n    text-align: left;\n    height: 100px;\n}\n```\n\n### Using string rule matchers\n\nString matchers will match a rule if the entire selector of the rule matches exactly with the string.\n\n```javascript\npostcssComments({\n    rulesMatchers: [\n       {\n            matcher: ['.link', '.test-class'],\n            prepend: 'Using an array of string matchers'\n       },\n       {\n            matcher: '.link:visited',\n            append: 'Using a unique string matcher'\n       }\n    ]\n})\n```\n\n#### Output\n\n```css\n.test1, .test2 {\n    color: #666;\n    padding-right: 20px;\n    width: 100%;\n}\n\n/* Using an array of string matchers */\n.link {\n    color: red;\n}\n\n.link:hover {\n    color: red;\n}\n\n.link:visited {\n    color: red;\n}\n/* Using a unique string matcher */\n\n/* Using an array of string matchers */\n.test-class {\n    text-align: left;\n    height: 100px;\n}\n```\n\n### Using RegExp rule matchers\n\nRegular Expressions matchers are more flexible. They allow one to match rules without specifying exactly the string of their selectors using a Regular Expression pattern instead.\n\n```javascript\npostcssComments({\n    rulesMatchers: [\n       {\n            matcher: [/^\\.test\\d+/, /^\\.link:\\w+$/],\n            prepend: 'Using an array of RegExp matchers'\n       },\n       {\n            matcher: /\\.test-\\w+$/,\n            append: 'Using a single regular expression'\n       }\n    ]\n})\n```\n\n#### Output\n\n```css\n/* Using an array of RegExp matchers */\n.test1, .test2 {\n    color: #666;\n    padding-right: 20px;\n    width: 100%;\n}\n\n.link {\n    color: red;\n}\n\n/* Using an array of RegExp matchers */\n.link:hover {\n    color: red;\n}\n\n/* Using an array of RegExp matchers */\n.link:visited {\n    color: red;\n}\n\n.test-class {\n    text-align: left;\n    height: 100px;\n}\n/* Using a single regular expression */\n```\n\nNotes\n---\n\n1. String matchers and Regular Expression matchers can be mixed in the same macther array.\n1. Only the first matcher is used. If a rule matches a matcher, the `append` or `prepend` comments are inserted and it doesn‘t continue checking the next matchers on the array.\n2. Regular Expressions matchers cannot have [flags], if you set flags, they will be ignored.\n3. If you do not use PostCSS, add it according to [official docs]\nand set this plugin in settings.\n\n[PostCSS]: https://github.com/postcss/postcss\n[RTLCSS]: https://rtlcss.com/learn/usage-guide/control-directives/\n[PostCSS RTLCSS]: https://github.com/elchininet/postcss-rtlcss#control-directives\n[flags]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags\n[official docs]: https://github.com/postcss/postcss#usage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felchininet%2Fpostcss-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felchininet%2Fpostcss-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felchininet%2Fpostcss-comments/lists"}