admin管理员组文章数量:1354751
Why does my tailwind not work with my components in my packages/components/src
files?
It works in my apps/my-app
but when I import my component from packages it does not apply TailwindCSS on my component.
I have my app.css
in packages/styles
. What should I do?
Why does my tailwind not work with my components in my packages/components/src
files?
It works in my apps/my-app
but when I import my component from packages it does not apply TailwindCSS on my component.
I have my app.css
in packages/styles
. What should I do?
1 Answer
Reset to default 1TailwindCSS v4 arrived with automatic source detection. This feature scans all files and searches for used class names to generate the compiled CSS. However, it ignores paths listed in the .gitignore
file, meaning it typically skips node_modules
directories; which is generally a good thing.
- Which files are scanned - TailwindCSS v4 Docs
- Automatic Source Detection from TailwindCSS v4 - StackOverflow
To make it detect custom packages despite node_modules
being ignored by .gitignore
, you can use the @source
directive as follows:
- Explicitly registering sources - TailwindCSS v4 Docs
./src/app.css
/* detects everything except the paths in the .gitignore file */
@import "tailwindcss";
/* if node_modules is ignored in .gitignore, it is possible to perform detection in its subdirectories */
@source "../node_modules/mypackage-first";
@source "../node_modules/mypackage-second/subdirectory/etc";
It is important to note that the path passed to the @source
directive is relative and should be defined based on the location of the CSS file.
If TailwindCSS doesn't detect anything, it's possible that you disabled source detection during import using source(none)
. In this case, TailwindCSS will only scan the paths specified with the @source
directive.
./src/app.css
/* source(none) disables all detection, so it doesn't detect anything by default */
@import "tailwindcss" source(none);
/* in this case, it only detects the paths specified with @source */
@source "./"; /* relative path for src, since app.css in my example is located in src */
@source "../node_modules/mypackage-first";
@source "../node_modules/mypackage-second/subdirectory/etc";
本文标签: tailwind cssTailwindCSS v4 does not apply styles in packagescomponentsStack Overflow
版权声明:本文标题:tailwind css - TailwindCSS v4 does not apply styles in packagescomponents - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744023554a2577646.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
And i cant use @source because of sveltekit + vite
- Why? It's new CSS-first directive by TailwindCSS v4. – rozsazoltan Commented Mar 28 at 17:49