Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

postcss-plugin.md 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # PostCSS plugin
  2. As with any other [PostCSS plugin](https://github.com/postcss/postcss#plugins), you can use stylelint's PostCSS plugin either with a [PostCSS runner](https://github.com/postcss/postcss#runners) or with the PostCSS JS API directly.
  3. _However, if a dedicated stylelint task runner plugin [is available](../integrations/task-runner.md) (e.g. [gulp-stylelint](https://github.com/olegskl/gulp-stylelint)) we recommend you use that rather than this plugin, as they provide better reporting._
  4. ## Options
  5. The PostCSS plugin uses the [standard options](options.md), _except the `syntax` and `customSyntax` options_. Instead, the syntax must be set within the [PostCSS options](https://github.com/postcss/postcss#options) as there can only be one parser/syntax in a pipeline.
  6. ## Usage examples
  7. We recommend you lint your CSS before applying any transformations. You can do this by either:
  8. - creating a separate lint task that is independent of your build one.
  9. - using the [`plugins` option](https://github.com/postcss/postcss-import#plugins) of [`postcss-import`](https://github.com/postcss/postcss-import) or [`postcss-easy-import`](https://github.com/TrySound/postcss-easy-import) to lint your files before any transformations.
  10. - placing stylelint at the beginning of your plugin pipeline.
  11. You'll also need to use a reporter. _The stylelint plugin registers warnings via PostCSS_. Therefore, you'll want to use it with a PostCSS runner that prints warnings or another PostCSS plugin whose purpose is to format and print warnings (e.g. [`postcss-reporter`](https://github.com/postcss/postcss-reporter)).
  12. ### Example A
  13. A separate lint task that uses the plugin via the PostCSS JS API to lint Less using [`postcss-less`](https://github.com/shellscape/postcss-less).
  14. ```js
  15. const fs = require("fs");
  16. const less = require("postcss-less");
  17. const postcss = require("postcss");
  18. // Code to be processed
  19. const code = fs.readFileSync("input.less", "utf8");
  20. postcss([
  21. require("stylelint")({
  22. /* your options */
  23. }),
  24. require("postcss-reporter")({ clearReportedMessages: true })
  25. ])
  26. .process(code, {
  27. from: "input.less",
  28. syntax: less
  29. })
  30. .then(() => {})
  31. .catch((err) => console.error(err.stack));
  32. ```
  33. The same pattern can be used to lint Less, SCSS or [SugarSS](https://github.com/postcss/sugarss) syntax.
  34. ### Example B
  35. A combined lint and build task where the plugin is used via the PostCSS JS API, but within [`postcss-import`](https://github.com/postcss/postcss-import) (using the its `plugins` option) so that the source files are linted before any transformations.
  36. ```js
  37. const fs = require("fs");
  38. const postcss = require("postcss");
  39. const stylelint = require("stylelint");
  40. // CSS to be processed
  41. const css = fs.readFileSync("lib/app.css", "utf8");
  42. postcss([
  43. require("postcss-import")({
  44. plugins: [
  45. require("stylelint")({
  46. /* your options */
  47. })
  48. ]
  49. }),
  50. require("postcss-preset-env"),
  51. require("postcss-reporter")({ clearReportedMessages: true })
  52. ])
  53. .process(css, {
  54. from: "lib/app.css",
  55. to: "app.css"
  56. })
  57. .then((result) => {
  58. fs.writeFileSync("app.css", result.css);
  59. if (result.map) {
  60. fs.writeFileSync("app.css.map", result.map);
  61. }
  62. })
  63. .catch((err) => console.error(err.stack));
  64. ```