{"name":"postcss-prefix-selector","description":"Prefix all CSS rules with a selector","version":"1.3.0","author":{"name":"Jonathan Ong","email":"me@jongleberry.com","url":"http://jongleberry.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jonathanong/postcss-prefix-selector.git"},"dependencies":{"postcss":"^5.0.8"},"devDependencies":{"istanbul":"0","mocha":"2"},"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"},"keywords":["postcss","prefix","selectors","postcss-plugin"],"files":["index.js"],"gitHead":"cba4e8941254abd33593c14af5b566ed66f68af8","bugs":{"url":"https://github.com/jonathanong/postcss-prefix-selector/issues"},"homepage":"https://github.com/jonathanong/postcss-prefix-selector#readme","_id":"postcss-prefix-selector@1.3.0","_shasum":"49f9a1f5fa9930aff15621436fc3174710300b1c","_from":".","_npmVersion":"2.11.2","_nodeVersion":"0.12.5","_npmUser":{"name":"valentin-radulescu-hs","email":"valentin.radulescu@hootsuite.com"},"dist":{"shasum":"49f9a1f5fa9930aff15621436fc3174710300b1c","tarball":"http://registry-npm.ywwl.com/postcss-prefix-selector/download/postcss-prefix-selector-1.3.0.tgz","integrity":"sha512-ZqtxQ647QZb9DsB1iLrRAzKDvxVsIthvW83f1ISUvcItLaOmyQQW1LjpnL9lbjHpIKZPOW6gVsxJF7pqdhrloQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFylWp8oIa8/MMVNa5GaNhpCSCJgthloEaVB4GFHH4ELAiEAkZxZkHf7SZCx3F6jgXRkEbvr30n8jVB5OJn7JJ+sX3U="}],"size":2149,"noattachment":false,"key":"/postcss-prefix-selector/-/postcss-prefix-selector-1.3.0.tgz"},"maintainers":[{"name":"jongleberry","email":"jonathanrichardong@gmail.com"},{"name":"ndpnt","email":"npg.dupont@gmail.com"},{"name":"valentin-radulescu-hs","email":"valentin.radulescu@hootsuite.com"}],"directories":{},"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":1443727638268,"_cnpm_publish_time":1443727638268,"dist-tags":{"latest":"2.2.1"}}