# esbuild-plugin-postcss2

> Use postcss with esbuild

Latest version **0.1.2** (published 2022-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install esbuild-plugin-postcss2
pnpm add esbuild-plugin-postcss2
yarn add esbuild-plugin-postcss2
bun add esbuild-plugin-postcss2
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2022-02-01 |
| First published | 2021-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Marton Lederer |
| Maintainers | martondev |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-postcss2
- Repository: https://github.com/martonlederer/esbuild-plugin-postcss2
- npm.io page: https://npm.io/package/esbuild-plugin-postcss2

## Dependencies (9)

- [tmp](https://npm.io/package/tmp.md) ^0.2.1
- [less](https://npm.io/package/less.md) ^4.x
- [sass](https://npm.io/package/sass.md) ^1.x
- [stylus](https://npm.io/package/stylus.md) ^0.x
- [postcss](https://npm.io/package/postcss.md) 8.x
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.1.0
- [autoprefixer](https://npm.io/package/autoprefixer.md) ^10.2.5
- [resolve-file](https://npm.io/package/resolve-file.md) ^0.3.0
- [postcss-modules](https://npm.io/package/postcss-modules.md) ^4.0.0

## Recent versions

- 0.1.2 (latest) — 2022-02-01
- 0.1.1 — 2021-11-25
- 0.1.0 — 2021-08-22
- 0.0.10 — 2021-08-22
- 0.0.9 — 2021-04-08
- 0.0.8 — 2021-04-05
- 0.0.7 — 2021-03-23
- 0.0.6 — 2021-02-21
- 0.0.5 — 2021-02-20
- 0.0.4 — 2021-02-20
- 0.0.3 — 2021-02-20
- 0.0.2 — 2021-02-20
- 0.0.1 — 2021-02-20

## README

# esbuild-plugin-postcss2

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.

## Install

```sh
yarn add -D esbuild-plugin-postcss2
```

or

```sh
npm i -D esbuild-plugin-postcss2
```

## Usage

Add the plugin to your esbuild plugins:

```js
const esbuild = require("esbuild");
const postCssPlugin = require("esbuild-plugin-postcss2");

esbuild.build({
  ...
  plugins: [
    postCssPlugin.default()
  ]
  ...
});
```

### PostCSS plugins

Add your desired PostCSS plugin to the plugins array:

```js
const autoprefixer = require("autoprefixer");

esbuild.build({
  ...
  plugins: [
    postCssPlugin.default({
      plugins: [autoprefixer]
    })
  ]
  ...
});
```

### CSS modules

PostCSS modules are enabled by default. You can pass in a config or disable it with the `modules` field:

```js
postCssPlugin.default({
  // pass in `postcss-modules` custom options
  // set to false to disable
  modules: {
    getJSON(cssFileName, json, outputFileName) {
      const path = require("path");
      const cssName = path.basename(cssFileName, ".css");
      const jsonFileName = path.resolve("./build/" + cssName + ".json");

      fs.writeFileSync(jsonFileName, JSON.stringify(json));
    }
  }
});
```

As per standard any file having `module` before the extension (ie `somefile.module.css`) will be treated as a module.
The option `fileIsModule` allows to override this behavior.

```js
postCssPlugin.default({
  // pass a custom `fileIsModule` option to tell whether a file should be treated as a module
  // in this example we want everything to be a module except file finishing with `global.css`
  fileIsModule: (filepath) => !filepath.endsWith(".global.css")
});
```

### Preprocessors

To use preprocessors (`sass`, `scss`, `stylus`, `less`), just add the desired preprocessor as a `devDependency`:

```sh
yarn add -D sass
```

---
_Source: https://npm.io/package/esbuild-plugin-postcss2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
