Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

2 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # esbuild-plugin-postcss2
  2. This plugin is an optimized, type-friendly version of [esbuild-plugin-postcss](https://github.com/deanc/esbuild-plugin-postcss). It supports CSS preprocessors and CSS modules.
  3. ## Install
  4. ```sh
  5. yarn add -D esbuild-plugin-postcss2
  6. ```
  7. or
  8. ```sh
  9. npm i -D esbuild-plugin-postcss2
  10. ```
  11. ## Usage
  12. Add the plugin to your esbuild plugins:
  13. ```js
  14. const esbuild = require("esbuild");
  15. const postCssPlugin = require("esbuild-plugin-postcss2");
  16. esbuild.build({
  17. ...
  18. plugins: [
  19. postCssPlugin.default()
  20. ]
  21. ...
  22. });
  23. ```
  24. ### PostCSS plugins
  25. Add your desired PostCSS plugin to the plugins array:
  26. ```js
  27. const autoprefixer = require("autoprefixer");
  28. esbuild.build({
  29. ...
  30. plugins: [
  31. postCssPlugin.default({
  32. plugins: [autoprefixer]
  33. })
  34. ]
  35. ...
  36. });
  37. ```
  38. ### CSS modules
  39. PostCSS modules are enabled by default. You can pass in a config or disable it with the `modules` field:
  40. ```js
  41. postCssPlugin.default({
  42. // pass in `postcss-modules` custom options
  43. // set to false to disable
  44. modules: {
  45. getJSON(cssFileName, json, outputFileName) {
  46. const path = require("path");
  47. const cssName = path.basename(cssFileName, ".css");
  48. const jsonFileName = path.resolve("./build/" + cssName + ".json");
  49. fs.writeFileSync(jsonFileName, JSON.stringify(json));
  50. }
  51. }
  52. });
  53. ```
  54. As per standard any file having `module` before the extension (ie `somefile.module.css`) will be treated as a module.
  55. The option `fileIsModule` allows to override this behavior.
  56. ```js
  57. postCssPlugin.default({
  58. // pass a custom `fileIsModule` option to tell whether a file should be treated as a module
  59. // in this example we want everything to be a module except file finishing with `global.css`
  60. fileIsModule: (filepath) => !filepath.endsWith(".global.css")
  61. });
  62. ```
  63. ### Preprocessors
  64. To use preprocessors (`sass`, `scss`, `stylus`, `less`), just add the desired preprocessor as a `devDependency`:
  65. ```sh
  66. yarn add -D sass
  67. ```