# esbuild-plugin-postcss

> esbuild的postcss插件用于支持ts模块中支持引入css

Latest version **0.3.0** (published 2025-04-17) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2025-04-17 |
| First published | 2022-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shy9120 |
| Maintainers | shy2850 |
| Keywords | esbuild, postcss |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-postcss
- Repository: git@gitee.com:shy9120/esbuild-plugin-postcss
- npm.io page: https://npm.io/package/esbuild-plugin-postcss

## Dependencies (4)

- [less](https://npm.io/package/less.md) ^4.3.0
- [esbuild](https://npm.io/package/esbuild.md) ^0.25.2
- [postcss](https://npm.io/package/postcss.md) ^8.5.3
- [postcss-modules](https://npm.io/package/postcss-modules.md) ^6.0.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2025-04-17
- 0.2.1 — 2023-05-30
- 0.2.0 — 2023-04-26
- 0.1.4 — 2023-01-13
- 0.1.1 — 2022-11-02
- 0.1.0 — 2022-10-16
- 0.0.2 — 2022-06-27
- 0.0.1 — 2022-06-26

## README

# esbuild-plugin-postcss

#### 介绍
esbuild的postcss插件用于支持ts模块中支持引入css

#### 使用说明

`npm i esbuild-plugin-postcss --save-dev`

.esbuildrc.js
```js
const PluginPostCSS = require('esbuild-plugin-postcss').default
esbuild({
    ...
    plugins: [
        PluginPostCSS({
            // 根据less文件生成.d.ts文件 (from v0.1.1)
            declaration: true,
        })
    ],
    loader: {
        '.tsx': 'tsx',
        '.ts': 'ts',
    },
})
```

index.less
```less
.index {
    background-color: red;
    font: 500 24px/48px "Microsoft Yahei";
    .tab {
        background-color: black;
        color: bisque;
    }
}
```

App.tsx
```jsx
import style from "./style.less"

const App = () => {
    return <div className={style.index}>
        <div>
            <span>标题</span>
        </div>
        <div className={style.tab}>tab1</div>
        <div className={style.tab}>tab2</div>
        <div className={style.tab}>tab3</div>
    </div>
}
```

> PS: typescript 支持 `.less`资源可能需要配置全局module
```ts   
declare module "*.less" {
    const content: Record<string, string>;
    export default content;
}
```

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