{"id":19653004,"url":"https://github.com/csstools/postcss-visitor","last_synced_at":"2025-04-28T17:31:05.322Z","repository":{"id":57328667,"uuid":"79577551","full_name":"csstools/postcss-visitor","owner":"csstools","description":"Transform CSS with visitor-based plugins","archived":true,"fork":false,"pushed_at":"2017-01-23T14:40:45.000Z","size":15,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-21T21:40:27.295Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/jonathantneal/postcss-visitor","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csstools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-20T16:49:26.000Z","updated_at":"2024-12-27T18:35:26.000Z","dependencies_parsed_at":"2022-09-13T19:50:56.037Z","dependency_job_id":null,"html_url":"https://github.com/csstools/postcss-visitor","commit_stats":null,"previous_names":["jonathantneal/postcss-visitor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-visitor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-visitor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-visitor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-visitor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csstools","download_url":"https://codeload.github.com/csstools/postcss-visitor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250435371,"owners_count":21430267,"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-11-11T15:12:53.566Z","updated_at":"2025-04-28T17:31:05.263Z","avatar_url":"https://github.com/csstools.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostCSS Visitor [\u003cimg src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS Logo\" width=\"90\" height=\"90\" align=\"right\"\u003e][postcss]\n\n[![NPM Version][npm-img]][npm-url]\n[![Build Status][cli-img]][cli-url]\n[![Licensing][lic-img]][lic-url]\n[![Changelog][log-img]][log-url]\n[![Gitter Chat][git-img]][git-url]\n\n[PostCSS Visitor] lets you transform CSS with visitors. No more walking the CSS tree with every plugin.\n\n```js\nrequire('postcss-visitor').process(\n\t'figure { width: 100%; height: 100%; } ',\n\t[{\n\t\tdecl(node) {\n\t\t\tif (node.prop === 'width') node.remove()\n\t\t}\n\t}]\n).then(\n\t(result) =\u003e result.css // figure { height: 100%; }\n)\n```\n\n[PostCSS Visitor] also lets you create [PostCSS] plugins that use visitors.\n\n```js\n// create a visitor plugin\nmodule.exports = require('postcss-visitor').plugin(\n\t'postcss-visitor-example',\n\t(/* Options */) =\u003e ({\n\t\tdecl(node) {\n\t\t\t// do something with a declaration\n\t\t}\n\t})\n)\n```\n\nBy default, visitor plugins still work with [PostCSS].\n\n```js\nrequire('postcss')([\n\t// use the visitor plugin as a postcss plugin\n\trequire('postcss-visitor-example')(/* Options */)\n])\n```\n\nThe best practice is to use visitor plugins with [PostCSS Visitor]. These plugins will cooperate with each other and run much faster.\n\n```js\nrequire('postcss')([\n\t// use plugins as visitors\n\trequire('postcss-visitor')([\n\t\trequire('postcss-visitor-example').asVisitor(/* Options */),\n\t\trequire('postcss-visitor-another-example').asVisitor(/* Options */),\n\t\trequire('postcss-visitor-a-third-example').asVisitor(/* Options */)\n\t])\n])\n```\n\nAll [PostCSS Visitor] plugins run in the order of the tree first, and then the order they are added. This prevents many conflicts in standard [PostCSS] plugins and allows new kinds of plugins to be written.\n\n## Options\n\nIf the options passed into [PostCSS Visitor] are an array, then the array will be used to load any plugins or transforms.\n\nIf the options are an object, then the `plugins` key will be used to load any plugins or transforms.\n\nPlugins will be executed before walkin the DOM, and they will receive as an argument the options passed into [PostCSS Visitor].\n\n## Visitors\n\nVisitors are created by assigning functions to keys on an object. Anytime a node with a type matching that key is encountered, its function will be run.\n\nVisitors may target constructs like at-rules, rules, and declarations, but they may also target more specific nodes, like a pseudo selector within a selector, or a function within a value.\n\nRead [VISITORS.md] to learn more.\n\n## API\n\nThe [PostCSS Visitor] API allows you to create visitor-based plugins that still work with [PostCSS] on their own.\n\nRead [API.md] to learn more.\n\n## Usage\n\nAdd [PostCSS Visitor] to your build tool:\n\n```bash\nnpm install postcss-visitor --save-dev\n```\n\n#### Node\n\nUse [PostCSS Visitor] to process your CSS:\n\n```js\nrequire('postcss-visitor').process(YOUR_CSS, /* options, plugins, visitors */)\n```\n\n#### PostCSS\n\nAdd [PostCSS] to your build tool:\n\n```bash\nnpm install postcss --save-dev\n```\n\nUse [PostCSS Visitor] as a plugin:\n\n```js\npostcss([\n\trequire('postcss-visitor')(/* options, plugins, visitors */)\n]).process(YOUR_CSS, /* options */)\n```\n\n#### Gulp\n\nAdd [Gulp PostCSS] to your build tool:\n\n```bash\nnpm install gulp-postcss --save-dev\n```\n\nUse [PostCSS Visitor] in your Gulpfile:\n\n```js\nvar postcss = require('gulp-postcss')\n\ngulp.task('css', function () {\n\treturn gulp.src('./src/*.css').pipe(\n\t\tpostcss([\n\t\t\trequire('postcss-visitor')(/* options, plugins, visitors */)\n\t\t])\n\t).pipe(\n\t\tgulp.dest('.')\n\t)\n})\n```\n\n#### Grunt\n\nAdd [Grunt PostCSS] to your build tool:\n\n```bash\nnpm install grunt-postcss --save-dev\n```\n\nUse [PostCSS Visitor] in your Gruntfile:\n\n```js\ngrunt.loadNpmTasks('grunt-postcss')\n\ngrunt.initConfig({\n\tpostcss: {\n\t\toptions: {\n\t\t\tuse: [\n\t\t\t\trequire('postcss-visitor')(/* options, plugins, visitors */)\n\t\t\t]\n\t\t},\n\t\tdist: {\n\t\t\tsrc: '*.css'\n\t\t}\n\t}\n})\n```\n\n[npm-url]: https://www.npmjs.com/package/postcss-visitor\n[npm-img]: https://img.shields.io/npm/v/postcss-visitor.svg\n[cli-url]: https://travis-ci.org/jonathantneal/postcss-visitor\n[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-visitor.svg\n[lic-url]: LICENSE.md\n[lic-img]: https://img.shields.io/npm/l/postcss-visitor.svg\n[log-url]: CHANGELOG.md\n[log-img]: https://img.shields.io/badge/changelog-md-blue.svg\n[git-url]: https://gitter.im/postcss/postcss\n[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg\n\n[`asVisitor()`]: API.md#pluginasvisitor\n[API.md]: API.md\n[Gulp PostCSS]: https://github.com/postcss/gulp-postcss\n[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss\n[PostCSS]: https://github.com/postcss/postcss\n[PostCSS Visitor]: https://github.com/jonathantneal/postcss-visitor\n[VISITORS.md]: VISITORS.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fpostcss-visitor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsstools%2Fpostcss-visitor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fpostcss-visitor/lists"}