{"name":"postcss-prefix-selector","description":"Prefix all CSS rules with a selector","version":"1.9.0","author":{"name":"Jonathan Ong","email":"me@jongleberry.com","url":"http://jongleberry.com"},"contributors":[{"name":"Valentin Radulescu","email":"hi@valentin.io","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":"^4.0.2","istanbul":"~0.4.5","lint-staged":"^10.0.3","mocha":"~7.2.0","prettier":"^2.0.0"},"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","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"],"husky":{"hooks":{"pre-commit":"lint-staged"}},"gitHead":"e82c5d3e3b72bcf29d774fed3f099eebf8635cec","_id":"postcss-prefix-selector@1.9.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-tTUHUNP+/Qfgg+fvbljUIeLs1ijICWb8+CT3bZM2joE2pkd+EnuBzSfZNHY2RMmozNRp44yEFv+I+6IIiLcoCg==","shasum":"db549802b79f9f91f7419c8c1f86d31d974aff5e","tarball":"http://registry-npm.ywwl.com/postcss-prefix-selector/download/postcss-prefix-selector-1.9.0.tgz","fileCount":4,"unpackedSize":9251,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgSzsvCRA9TVsSAnZWagAAnHIQAJp7PYqkNCCZF7mIZhpS\nR7o4VNiY7P4e8GlG/7oOmWW/2O2ZYdCXiV9AZOPS1swNubLcEs6XwlFmz7h7\n+YirAv4u8C3jQq4pGcIT1zrv0MCeXgi96zG+4lBJFW1pQicUjSO1MsbwKmLD\nfDcB+9E/NCfPSP72Cabja3XsIUUev90lDYWhZ6P2iTyJnna8by5+ykLUb2su\nRVUvrAg6IpY/1bCDRg5QKyANmlPzlXCJLZHGGcSHUoh1cd/UBLSe3eCeUf1l\nvbrmn7+ZyRGdXL8Y7QGBO3HuCoospfdvtzHULhbgxdeHbnSewo5nVD6q4FR5\npyexvY/DzocPzGkkmckpIggOzUJbdTcAuJqLK5wdK8WuMOq7jf5kWCN/7SHQ\nX90m4nuEkQT2SRg2N39uOvYaUfyfsFELjZTxNlxLMNbhzfCRaH+SdZJefeK2\nysL1NzfFpbgSr/VXjwEPg9B8bhdpmnwVzarVvxOfyHT/czE5+IvoRdcGpdBA\ns8nsuerJ+R8XQ31QOXXuCA89YXUQzptqdAISk8iZkbw3OyNsJWWLzRgejot0\nwLn8Rud+sVKxDBti/G/XZVpnarLktrp217ygmI6s6RTToiXFSB4ayH0PiShC\nPrPAoj4yazn711/wA8sQ7gyjx1n4gBElzC6p4lOwM9Tjz0fjc5kIy1vqzbKi\nD7ky\r\n=j1RJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYRqBRyjChmo0ZmiYAxsszsqSUOY0BH9eMz2arnRSS/AIgaeRmKwf3Ho60ZS9+Mi0SVak9GtHII56Mnl5BvB0Dyds="}],"size":3558,"noattachment":false,"key":"/postcss-prefix-selector/-/postcss-prefix-selector-1.9.0.tgz"},"_npmUser":{"name":"valentin-radulescu-hs","email":"radulescu.valentin@gmail.com"},"directories":{},"maintainers":[{"name":"jongleberry","email":"jonathanrichardong@gmail.com"},{"name":"ndpnt","email":"npg.dupont@gmail.com"},{"name":"valentin-radulescu-hs","email":"radulescu.valentin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/postcss-prefix-selector_1.9.0_1615543086964_0.7500474885170068"},"_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":1615543087113,"_cnpm_publish_time":1615543087113,"dist-tags":{"latest":"2.2.1"}}