最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - How to avoid css bloat when using a tailwindcss component library? - Stack Overflow

programmeradmin3浏览0评论

I built a component library that uses tailwindcss. Now I'm wondering how best to specify the source to avoid css bloat. The ui-library offers lots of components, but my app just use a few of them. I.e.

import { Button } from "shared-ui/button"; // Button contains tailwindcss classes 

If I add the source like this:

@source "node_modules/shared-ui/dist/**/*.js'"

all components are parsed and unnecessary css-directives land in my result-app-css file. How to fix this?

Thanks!

I built a component library that uses tailwindcss. Now I'm wondering how best to specify the source to avoid css bloat. The ui-library offers lots of components, but my app just use a few of them. I.e.

import { Button } from "shared-ui/button"; // Button contains tailwindcss classes 

If I add the source like this:

@source "node_modules/shared-ui/dist/**/*.js'"

all components are parsed and unnecessary css-directives land in my result-app-css file. How to fix this?

Thanks!

Share Improve this question edited Mar 8 at 19:09 Wongjn 25.3k4 gold badges20 silver badges44 bronze badges asked Mar 8 at 7:40 wuarminwuarmin 4,0354 gold badges20 silver badges37 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

This now depends on where the CSS is located where you declare the sources. It's better to use a relative path:

./src/global.css

@import "tailwindcss";

@source "./../node_modules/shared-ui/dist/**/*.js"; /* without ' char */

The node_modules folder is automatically ignored by gitignore, so you can safely add the shared-ui package to the discovery source list.

However, I wouldn't define the files myself; the automatic source detection will handle it based on the path, you only need to add the folder:

./src/global.css

@import "tailwindcss";

@source "./../node_modules/shared-ui/dist";
  • @source directive - TailwindCSS v4 Docs
发布评论

评论列表(0)

  1. 暂无评论