Skip to content

Commit 9234f59

Browse files
authored
docs: update README (#12)
- Add detailed usages - Add Credits
1 parent ea6e636 commit 9234f59

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

README.md

+88-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ An Rsbuild plugin to integrate with [Tailwind CSS](https://tailwindcss.com/) V3.
1010
<a href="https://npmcharts.com/compare/rsbuild-plugin-tailwindcss?minimal=true"><img src="https://img.shields.io/npm/dm/rsbuild-plugin-tailwindcss.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
1111
</p>
1212

13+
## Why?
14+
15+
Tailwind CSS is able to remove unused CSS classes through [Content Configuration](https://tailwindcss.com/docs/content-configuration). However, its accuracy may be insufficient when:
16+
17+
- Using multiple entries
18+
- Using a Tailwind CSS-based component library
19+
20+
This plugin uses the Rspack module graph to override the `content` configuration with imported modules, generating Tailwind CSS output _**based on usage**_.
21+
1322
## Usage
1423

1524
Install:
1625

1726
```bash
18-
npm add rsbuild-plugin-tailwindcss -D
27+
npm add tailwindcss@3 rsbuild-plugin-tailwindcss -D
1928
```
2029

2130
Add plugin to your `rsbuild.config.ts`:
@@ -29,6 +38,84 @@ export default {
2938
};
3039
```
3140

41+
### Custom Tailwind CSS Configuration
42+
43+
Create a `tailwind.config.js` file at the root of the project:
44+
45+
```js
46+
/** @type {import('tailwindcss').Config} */
47+
export default {
48+
theme: {
49+
colors: {
50+
blue: "#1fb6ff",
51+
purple: "#7e5bef",
52+
pink: "#ff49db",
53+
orange: "#ff7849",
54+
green: "#13ce66",
55+
yellow: "#ffc82c",
56+
"gray-dark": "#273444",
57+
gray: "#8492a6",
58+
"gray-light": "#d3dce6",
59+
},
60+
},
61+
};
62+
```
63+
64+
This will be auto-loaded by Rsbuild and applied by `rsbuild-plugin-tailwindcss`.
65+
66+
> [!NOTE]
67+
>
68+
> You don't need to add `content` in the `tailwind.config.js`. `rsbuild-plugin-tailwindcss` will add the imported modules for you.
69+
70+
### Custom PostCSS Options
71+
72+
Create a `postcss.config.js` file at the root of the project:
73+
74+
```js
75+
export default {
76+
plugins: {
77+
cssnano: process.env["NODE_ENV"] === "production" ? {} : false,
78+
},
79+
};
80+
```
81+
82+
> [!NOTE]
83+
>
84+
> You don't need to add `tailwindcss` in the `postcss.config.js`. `rsbuild-plugin-tailwindcss` will add the plugin for you.
85+
86+
Or use the [`tools.postcss`](https://rsbuild.dev/config/tools/postcss) option in `rsbuild.config.ts`.
87+
88+
## Options
89+
90+
### `config`
91+
92+
- Type: `string | undefined`
93+
- Default: `tailwind.config.js`
94+
95+
The path to custom Tailwind CSS configuration. Could be a relative path from the root of the project or an absolute path.
96+
97+
- Example:
98+
99+
```js
100+
// rsbuild.config.ts
101+
import { pluginTailwindCSS } from "rsbuild-plugin-tailwindcss";
102+
103+
export default {
104+
plugins: [
105+
pluginTailwindCSS({
106+
config: "./config/tailwind.config.js",
107+
}),
108+
],
109+
};
110+
```
111+
112+
## Credits
113+
114+
Thanks to:
115+
116+
- [Tailwind CSS V4](https://tailwindcss.com/blog/tailwindcss-v4-alpha) for the idea of purge CSS by module graph.
117+
- The [purge-tailwind-plugin](https://github.com/hardfist/purge-tailwind-plugin) created by [@hardfist](https://github.com/hardfist) for the implementation of the Rspack plugin.
118+
32119
## License
33120

34121
[MIT](./LICENSE).

0 commit comments

Comments
 (0)