{"name":"postcss-prefix-selector","description":"Prefix all CSS rules with a selector","version":"1.7.0","author":{"name":"Jonathan Ong","email":"me@jongleberry.com","url":"http://jongleberry.com"},"contributors":[{"name":"Valentin Radulescu","email":"valentin@radulescu.me","url":"https://valentin.io"}],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/RadValentin/postcss-prefix-selector.git"},"bugs":{"url":"https://github.com/RadValentin/postcss-prefix-selector/issues"},"homepage":"https://github.com/RadValentin/postcss-prefix-selector","dependencies":{"postcss":"^7.0.0"},"devDependencies":{"husky":"^1.0.0","istanbul":"~0.4.5","lint-staged":"^8.0.0","mocha":"~6.0.0","prettier":"^1.11.1"},"scripts":{"test":"mocha","test-cov":"istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot","test-travis":"istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot","precommit":"lint-staged","lint":"prettier --write '**/*.{js,css}'"},"lint-staged":{"*.js":["prettier --write","git add"]},"prettier":{"printWidth":80,"singleQuote":true},"keywords":["postcss","prefix","selectors","postcss-plugin","css","selector","plugin"],"gitHead":"8e8ae9c2c5c026270ad8f98628bcb6a4e66f9af2","_id":"postcss-prefix-selector@1.7.0","_npmVersion":"6.4.1","_nodeVersion":"11.1.0","_npmUser":{"name":"valentin-radulescu-hs","email":"radulescu.valentin@gmail.com"},"dist":{"integrity":"sha512-e6mFhNcqBTbFKd9Wvy4c84IxpvEBWX5+JWiEKDYBVE3UB4C7sho4QwLiKPohbHfnVy3pQhRYXFOf4bSBR84cQQ==","shasum":"a2bcc168d96e5d38bfc9ac2e71d3075f44e55236","tarball":"http://registry-npm.ywwl.com/postcss-prefix-selector/download/postcss-prefix-selector-1.7.0.tgz","fileCount":4,"unpackedSize":8073,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJccWmdCRA9TVsSAnZWagAA4/wP/0CdDeByfor5F9puJkrT\nKYBKbWziSYwGWBk/5MyGPBP/w8C2A6EQIxujnUV3/OH7J2FzgO9PzLi2rbjn\nc0d6eLg0h64qaLiHxj/10fHTbplQlJklqNFtaLqLJHgvRTfXOgQPdKyp0+SR\nI879M6c7C89MBN4EFz5GxfKNGpQaaofTFO/FSaIyb29HngiMxJUOOeleMmZF\nFjA6wHMV+Afus2PwUNb4LuR72+03nXDC4k8YFUjClZHNoqFVBAwmqLFvG5lK\np6ei/Eel85dpbXFxkm134XlffQBbbyT/dL2ZMvICELsV3Mr6g5SPZ57hYhQr\n/kWV/nfEv1H291od9xD2Qm30w7VGs1xk0QDQEdVrgBARUknNYWrAe/Sd7nQl\nFi/OS3Gix1n5fLQ5bheto0Rp13t+ekpbfBaLA667F6wkhIV9iNGIM93329wr\nhSGsdiHcryVEqCRVKFuv6gg1AL6CNw3pLo64jvUYcNvA7FUPIsUodCpcVITU\nPmqXUxRaKGLzy3GS3ACO5zAb691F/5Q+AB/616dpRn6dfcPKvw29B5ZEXO+h\nVq8GwsnUG2tiZmg4Mz96NC0H+XtDMaX49OEUsfuOuRfeLKNYnFW5C/LtQXzS\nw0AVM4TyZEh3rfC22+2zK/zpfr257Ym+7kiqVvrwhMYBdqKFATQ4pnAypFdE\n8izE\r\n=F3p1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGRLgJwvytPk523mhOwaTuHj70+xdaH/pKoEndcEhsPFAiEAtc/4t4AtKACgEnQc1ReiJHcZl+0ou6xRCocZ7U7loIs="}],"size":3257,"noattachment":false,"key":"/postcss-prefix-selector/-/postcss-prefix-selector-1.7.0.tgz"},"maintainers":[{"email":"jonathanrichardong@gmail.com","name":"jongleberry"},{"email":"npg.dupont@gmail.com","name":"ndpnt"},{"email":"radulescu.valentin@gmail.com","name":"valentin-radulescu-hs"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/postcss-prefix-selector_1.7.0_1550936477228_0.04454316517661394"},"_hasShrinkwrap":false,"readme":"# postcss-prefix-selector\r\n\r\n[![NPM version][npm-image]][npm-url]\r\n[![Test coverage][coveralls-image]][coveralls-url]\r\n[![License][license-image]][license-url]\r\n[![Downloads][downloads-image]][downloads-url]\r\n[![Gitpod ready-to-code][gitpod-image]][gitpod-url]\r\n\r\n> Prefix every CSS selector with a custom namespace `.a => .prefix .a`\r\n\r\n## Table of Contents\r\n\r\n- [Install](#install)\r\n- [Usage with PostCSS](#usage-with-postcss)\r\n- [Usage with Webpack](#usage-with-webpack)\r\n- [Usage with Vite](#usage-with-vite)\r\n- [Options](#options)\r\n- [Maintainer](#maintainer)\r\n- [Contribute](#contribute)\r\n- [License](#license)\r\n\r\n## Install\r\n\r\n```console\r\n$ npm install postcss-prefix-selector\r\n```\r\n\r\n## Usage with PostCSS\r\n\r\n```js\r\nconst prefixer = require('postcss-prefix-selector')\r\n\r\n// css to be processed\r\nconst css = fs.readFileSync(\"input.css\", \"utf8\")\r\n\r\nconst out = postcss().use(prefixer({\r\n  prefix: '.some-selector',\r\n  exclude: ['.c'],\r\n\r\n  // Optional transform callback for case-by-case overrides\r\n  transform: function (prefix, selector, prefixedSelector, filePath, rule) {\r\n    if (selector === 'body') {\r\n      return 'body' + prefix;\r\n    } else {\r\n      return prefixedSelector;\r\n    }\r\n  }\r\n})).process(css).css\r\n```\r\n\r\nUsing the options above and the CSS below...\r\n\r\n```css\r\nbody {\r\n  background: red;\r\n}\r\n\r\n.a, .b {\r\n  color: aqua;\r\n}\r\n\r\n.c {\r\n  color: coral;\r\n}\r\n```\r\n\r\nYou will get the following output\r\n\r\n```css\r\nbody.some-selector {\r\n  background: red;\r\n}\r\n\r\n.some-selector .a, .some-selector .b {\r\n  color: aqua;\r\n}\r\n\r\n.c {\r\n  color: coral;\r\n}\r\n```\r\n\r\n## Usage with webpack\r\n\r\nUse it like you'd use any other PostCSS plugin. If you also have `autoprefixer` in your webpack config then make sure that `postcss-prefix-selector` is called first. This is needed to avoid running the prefixer twice on both standard selectors and vendor specific ones (ex: `@keyframes` and `@webkit-keyframes`).\r\n\r\n```js\r\nmodule: {\r\n  rules: [{\r\n    test: /\\.css$/,\r\n    use: [\r\n      require.resolve('style-loader'),\r\n      require.resolve('css-loader'),\r\n      {\r\n        loader: require.resolve('postcss-loader'),\r\n        options: {\r\n          postcssOptions: {\r\n            plugins: {\r\n              \"postcss-prefix-selector\": {\r\n                prefix: '.my-prefix',\r\n                transform(prefix, selector, prefixedSelector, filePath, rule) {\r\n                  if (selector.match(/^(html|body)/)) {\r\n                    return selector.replace(/^([^\\s]*)/, `$1 ${prefix}`);\r\n                  }\r\n                  \r\n                  if (filePath.match(/node_modules/)) {\r\n                    return selector; // Do not prefix styles imported from node_modules\r\n                  }\r\n                  \r\n                  const annotation = rule.prev();\r\n                  if (annotation?.type === 'comment' && annotation.text.trim() === 'no-prefix') {\r\n                    return selector; // Do not prefix style rules that are preceded by: /* no-prefix */\r\n                  }\r\n\r\n                  return prefixedSelector;\r\n                },\r\n              },\r\n              autoprefixer: {\r\n                browsers: ['last 4 versions']\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    ]\r\n  }]\r\n}\r\n```\r\n\r\n\r\n## Usage with Vite\r\n\r\nFollowing the same way of Webpack but for Vite:\r\n\r\n```js\r\nimport prefixer from 'postcss-prefix-selector';\r\nimport autoprefixer from 'autoprefixer';\r\n\r\n...\r\n\r\nexport default defineConfig({\r\n...\r\n  css: {\r\n    postcss: {\r\n      plugins: [\r\n        prefixer({\r\n          prefix: '.my-prefix',\r\n          transform(prefix, selector, prefixedSelector, filePath, rule) {\r\n            if (selector.match(/^(html|body)/)) {\r\n              return selector.replace(/^([^\\s]*)/, `$1 ${prefix}`);\r\n            }\r\n\r\n            if (filePath.match(/node_modules/)) {\r\n              return selector; // Do not prefix styles imported from node_modules\r\n            }\r\n\r\n            const annotation = rule.prev();\r\n            if (annotation?.type === 'comment' && annotation.text.trim() === 'no-prefix') {\r\n              return selector; // Do not prefix style rules that are preceded by: /* no-prefix */\r\n            }\r\n\r\n            return prefixedSelector;\r\n          },\r\n        }),\r\n\r\n        autoprefixer({}) // add options if needed\r\n      ],\r\n    }\r\n  },\r\n...\r\n});  \r\n```\r\n\r\n## Options\r\n\r\n| Name | Type | Description |\r\n|-|-|-|\r\n| `prefix` | `string` | This string is added before every CSS selector |\r\n| `exclude` | `string[]` or `RegExp[]` | It's possible to avoid prefixing some selectors by passing an array of selectors |\r\n| `transform` | `Function` | In cases where you may want to use the prefix differently for different selectors, it is possible to pass in a custom transform method |\r\n| `ignoreFiles` | `string[]` or `RegExp[]` | List of ignored files for processing |\r\n| `includeFiles` | `string[]` or `RegExp[]` | List of included files for processing |\r\n\r\n## Maintainer\r\n\r\nThis project was originally created by [@jongleberry](https://github.com/jonathanong) and is being maintained by [@RadValentin](https://github.com/RadValentin). If you have any questions, feel free to ping the latter.\r\n\r\n## Contribute\r\n\r\nPlease contribute! If you have any questions or bugs, [open an issue](https://github.com/RadValentin/postcss-prefix-selector/issues/new). Or, open a pull request with a fix.\r\n\r\nThis project uses Mocha. If you submit a PR, please add appropriate tests and make sure that everything is green for your branch.\r\n\r\n## License\r\n\r\n[MIT](LICENSE) © 2015-2022 Jonathan Ong.\r\n\r\n[gitpod-image]: https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod\r\n[gitpod-url]: https://gitpod.io/#https://github.com/RadValentin/postcss-prefix-selector\r\n[npm-image]: https://img.shields.io/npm/v/postcss-prefix-selector.svg?style=flat-square\r\n[npm-url]: https://npmjs.org/package/postcss-prefix-selector\r\n[coveralls-image]: https://img.shields.io/coveralls/jonathanong/postcss-prefix-selector.svg?style=flat-square\r\n[coveralls-url]: https://coveralls.io/r/jonathanong/postcss-prefix-selector\r\n[license-image]: http://img.shields.io/npm/l/postcss-prefix-selector.svg?style=flat-square\r\n[license-url]: LICENSE\r\n[downloads-image]: http://img.shields.io/npm/dm/postcss-prefix-selector.svg?style=flat-square\r\n[downloads-url]: https://npmjs.org/package/postcss-prefix-selector\r\n","publish_time":1550936477431,"_cnpm_publish_time":1550936477431,"dist-tags":{"latest":"2.2.1"}}