---
title: "@farmfe/js-plugin-postcss"
locale: "en"
version: "1.x"
canonicalUrl: "https://farmfe.org/docs/1.x/plugins/official-plugins/js-postcss"
publicationStatus: "prerelease"
---

<a id="farmfejs-plugin-postcss"></a>
# @farmfe/js-plugin-postcss


Support ` postcss ` for Farm.


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/js-plugin-postcss postcss
```


**yarn**

```javascript
yarn add @farmfe/js-plugin-postcss postcss
```


**pnpm**

```javascript
pnpm add @farmfe/js-plugin-postcss postcss
```



<a id="usage"></a>
## Usage


```ts
import { UserConfig } from '@farmfe/core';
import farmJsPluginPostcss from '@farmfe/js-plugin-postcss';

const config: UserConfig = {
  plugins: [
    farmJsPluginPostcss({ /* options */ })
  ]
}
```


<a id="options"></a>
## Options


```ts
export type PostcssPluginOptions = {
  /**
   * @default undefined
   * postcss-load-config options. path default to farm.config.js root.
   */
  postcssLoadConfig?: {
    ctx?: postcssLoadConfig.ConfigContext;
    path?: string;
    options?: Parameters<typeof postcssLoadConfig>[2];
  };
  filters?: {
    resolvedPaths?: string[];
    moduleTypes?: string[];
  };
  implementation?: string;
};

```


<a id="postcssloadconfig"></a>
### postcssLoadConfig


Farm uses ` postcss-load-config ` to load ` postcss ` config, so you can use ` postcss-load-config `'s options. Refer to [postcss-load-config](<https://github.com/postcss/postcss-load-config>).


Example:


```ts
import path from 'node:path';
import { UserConfig } from '@farmfe/core';
import farmJsPluginPostcss from '@farmfe/js-plugin-postcss';

const config: UserConfig = {
  plugins: [
    farmJsPluginPostcss({
      postcssLoadConfig: {
        // load config from client/postcss.config.js
        path: path.join(process.cwd(), 'client')
      }
    })
  ]
}

export default config;
```


<a id="filters"></a>
### filters


Which files should be processed by ` postcss `. default to ` { moduleTypes: ['css'] } `.


- ` resolvedPaths `: Only files under these paths will be processed. Support regex.
- ` moduleTypes `: Only files with these module types will be processed. note that less/sass files should be processed by ` @farmfe/js-plugin-less `/` @farmfe/plugin-sass ` first.


` resolvedPaths ` and ` moduleTypes ` are unioned, which means files match any of them will be processed.


Example:


```ts
import { UserConfig } from '@farmfe/core';
import farmJsPluginPostcss from '@farmfe/js-plugin-postcss';

const config: UserConfig = {
  plugins: [
    farmJsPluginPostcss({
      filters: {
        // all files end with .custom-css will be processed
        resolvedPaths: ['\\.custom-css$'],
        moduleTypes: ['css']
      }
    })
  ]
}

export default config;
```


<a id="implementation"></a>
### implementation


` implementation ` package name of ` postcss `. Default to ` postcss `.
