Skip to content

Commit f84a8c7

Browse files
authored
docs: optimize Tailwind CSS build performance (#4343)
1 parent 7b9bbeb commit f84a8c7

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

website/docs/en/guide/basic/tailwindcss.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Tailwind CSS provides a [Tailwind CSS IntelliSense](https://github.com/tailwindl
129129

130130
You can install this plugin in VS Code to enable the autocompletion feature.
131131

132-
## Build Performance
132+
## Optimize Build Performance
133133

134134
When using Tailwind CSS, if the `content` field in `tailwind.config.js` is not correctly configured, this can lead to poor build performance and HMR performance. This is because Tailwind CSS internally matches files based on the glob defined in `content`. The more files it matches, the greater the performance overhead.
135135

@@ -148,6 +148,19 @@ module.exports = {
148148
};
149149
```
150150

151+
Sometimes, you may accidentally scan the `node_modules` directory, for example, when scanning files in a monorepo:
152+
153+
```js title="tailwind.config.js"
154+
module.exports = {
155+
content: [
156+
'./src/**/*.{html,js,ts,jsx,tsx}',
157+
// Incorrectly includes the `packages/ui/node_modules` directory
158+
// Should be '../../packages/ui/src/**/*.{html,js,ts,jsx,tsx}'
159+
'../../packages/ui/**/*.{html,js,ts,jsx,tsx}',
160+
],
161+
};
162+
```
163+
151164
## Optimize CSS Size
152165

153166
If you need to optimize the size of Tailwind CSS styles, you can try [rsbuild-plugin-tailwindcss](https://github.com/rspack-contrib/rsbuild-plugin-tailwindcss).

website/docs/en/guide/optimization/build-performance.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ The following are some general optimization methods, which can speed up the deve
1818

1919
Optimizing the number of modules referenced by the application can reduce the bundle size and improve build performance. Please read the [Bundle Size Optimization](/guide/optimization/optimize-bundle) section to learn some optimization methods.
2020

21+
### Optimize Tailwind CSS
22+
23+
When using Tailwind CSS, if the `content` field in `tailwind.config.js` is not correctly configured, this can lead to poor build performance and HMR performance.
24+
25+
Please refer to [Tailwind CSS - Optimize Build Performance](/guide/basic/tailwindcss#optimize-build-performance) for more details.
26+
2127
## Development optimization
2228

2329
The following are methods for improving performance in development mode.
2430

25-
## Enable Lazy Compilation
31+
### Enable Lazy Compilation
2632

2733
Enabling lazy compilation can significantly reduce the number of modules compiled at dev startup and improve startup time.
2834

website/docs/zh/guide/basic/tailwindcss.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Tailwind CSS 提供了 [Tailwind CSS IntelliSense](https://github.com/tailwindla
129129

130130
你可以在 VS Code 中安装该插件,即可开启自动补全功能。
131131

132-
## 构建性能
132+
## 优化构建性能
133133

134134
在使用 Tailwind CSS 时,如果没有正确地配置 `tailwind.config.js` 中的 `content` 字段,可能会导致构建性能和热更新性能下降。这是因为 Tailwind CSS 内部会基于 `content` 定义的 glob 来匹配文件,扫描的文件数量越多,产生的性能开销越大。
135135

@@ -148,6 +148,19 @@ module.exports = {
148148
};
149149
```
150150

151+
有时,你可能会不小心扫描 `node_modules` 目录,例如在 monorepo 中扫描其他包的文件时:
152+
153+
```js title="tailwind.config.js"
154+
module.exports = {
155+
content: [
156+
'./src/**/*.{html,js,ts,jsx,tsx}',
157+
// 错误地包含了 `packages/ui/node_modules` 目录
158+
// 正确写法为 '../../packages/ui/src/**/*.{html,js,ts,jsx,tsx}'
159+
'../../packages/ui/**/*.{html,js,ts,jsx,tsx}',
160+
],
161+
};
162+
```
163+
151164
## 优化样式体积
152165

153166
如果你需要优化 Tailwind CSS 的样式体积,欢迎尝试 [rsbuild-plugin-tailwindcss](https://github.com/rspack-contrib/rsbuild-plugin-tailwindcss)

website/docs/zh/guide/optimization/build-performance.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ Rsbuild 默认对构建性能进行了充分优化,但是随着使用场景变
1818

1919
对应用引用的模块数量进行优化,可以减少产物体积并提升构建性能,请阅读 [优化产物体积](/guide/optimization/optimize-bundle) 章节来了解一些优化方法。
2020

21+
### 优化 Tailwind CSS
22+
23+
在使用 Tailwind CSS 时,如果没有正确地配置 `tailwind.config.js` 中的 `content` 字段,可能会导致构建性能和热更新性能下降。
24+
25+
请参考 [Tailwind CSS - 优化构建性能](/guide/basic/tailwindcss#优化构建性能) 了解更多。
26+
2127
## 开发模式优化
2228

2329
以下是针对开发构建进行提速的方法。
2430

25-
## 启动 Lazy Compilation
31+
### 开启 Lazy Compilation
2632

2733
启用 lazy compilation 可以显著减少开发启动时编译的模块数量,从而提升启动时间。
2834

0 commit comments

Comments
 (0)