Tailwind classes from library components not applied in consuming app #19398
Replies: 2 comments 6 replies
-
Yes, have a CSS file in the library that has any neccessary The consumer would then So bare minimum: /* library/dist/index.css */
@source "./";/* consumer/src/index.css */
@import "tailwindcss";
@import "library/dist/index.css";Notice how the libary's CSS is uncompiled. We leave the compilation to the consumer.
No.
No. |
Beta Was this translation helpful? Give feedback.
-
|
If the component library is also based on TailwindCSS v4, then consider not shipping production-ready CSS in the library. Instead, import the source CSS, and TailwindCSS will map the library’s components using This can be taken even further: for example, if you have 1000 components but you only use 10 of them, it's beneficial if the unused 990 components' CSS does not end up in the production build. With |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a shared component library built with Shadcn UI + Tailwind v4+ TypeScript + tsup. Components like are exported and used in a separate consuming application. However, the Tailwind classes do not apply when using the library components. For example:
<Button variant="outline" size="icon" />renders a button with no styling.
If I run npx shadcn@latest add button in the consuming app, the same component gets styled correctly.
Library setup
{ "name": "shadcn-library", "type": "module", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", "files": ["dist", "src"], "dependencies": { /* ... */ } }tsupconfig
`import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
outDir: "dist",
format: ["esm"],
sourcemap: true,
clean: true,
dts: true,
splitting: false,
treeshake: true,
external: ["react", "react-dom"],
esbuildOptions(options) {
options.alias = {
"@": "./src",
};
options.jsx = "automatic";
},
});
**Consuming app setup**import type { Config } from "tailwindcss";export default {
content: [
"./src//*.{ts,tsx}",
"./node_modules/shadcn-library/src//*.{ts,tsx}"
],
theme: { extend: {} },
} satisfies Config;
`
Vite is used to build the consuming app.
Questions :
Is there a recommended way to publish Shadcn/Tailwind component libraries so Tailwind picks up classes automatically?
Does cva / clsx require special handling when used in a separate package?
Do I need to modify Vite or Tailwind config in the consuming app to handle this properly?
Beta Was this translation helpful? Give feedback.
All reactions