Skip to content

Using Vite to create a React library - Tailwind styles do not get bundled #14781

Answered by sadn1ck
mderazon asked this question in Q&A
Discussion options

You must be logged in to vote

Stackblitz doesn't save updates in node_modules, here's the relevant piece that I added

// package.json
"exports": {
  ".": {
    "types": "./dist/index.d.ts",
    "import": "./dist/ui-react.es.js",
    "require": "./dist/ui-react.umd.js",
    "styles": "./dist/style.css"
  },
  "./css": "./dist/style.css" // ← This
},
/* index.css */
@import '@oncehub/ui-react/css';

The (sort of) drawback with using tailwind for component libs is that tailwind just generates one single CSS file, so even if consumer uses 1 component, you have to import that entire CSS file in the consuming app (style.css in your dist)

I am not sure if there's a way to auto inject styles if a component is used, but you can…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@mderazon
Comment options

@sadn1ck
Comment options

Answer selected by mderazon
@mderazon
Comment options

@ManishMadan2882
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants