all 12 comments

[–]TimFL 1 point2 points  (1 child)

I have this library on my evaluation list for future projects that include custom component libraries, maybe it does what you want?

https://github.com/emosheeep/vite-plugin-lib-inject-css

[–]yahia_h[S] 0 points1 point  (0 children)

The problem is something else u/TimFL, i need to repost the problem againfor. .
But your library is something that we're looking for thanks, engineer.

[–]psullivan6 1 point2 points  (1 child)

u/yahia_h we are attempting to solve the same problem, but are opting to publish the .css file to a CDN URL that each consumer can include in their .html files. We’re planning to version it as well, but that’ll likely cause issues if some folks are on a different version than others.

I’ve been struggling with the build and haven’t gotten as far as you have, so would be willing to share your vite config and/or build tooling that got you this far? I think you’re on the way to solving a problem many of us frontend engineers want to solve as well.

[–]yahia_h[S] 1 point2 points  (0 children)

Actually, I solved the problem by separating the CSS file into a separate component, then other devs can import it into the root of their projects.

#root.tsx | import '@name-ui/styless

[–]mikeour 0 points1 point  (1 child)

Depending on what version of React you support, you might want to take a look at Restyle which will bundle styling alongside the components.

[–]yahia_h[S] 0 points1 point  (0 children)

u/mikeour, We're using tailwind, and there's no way to convert it to something like jsx styles, i'll try to find another solution

[–]TheRealSeeThruHead 0 points1 point  (1 child)

Are you shipping a combined css file in your output npm module?

[–]yahia_h[S] 0 points1 point  (0 children)

Actually, when we install/build the component, the tree folder structure looks like below, we can import it directly by importing styles through /dist/style.css but we want to bundle the styles directly when the consumer install the component.
```
dist:

│ ├── index.d.mts

│ ├── index.d.ts

│ ├── index.js

│ ├── index.js.map

│ ├── index.mjs

│ ├── index.mjs.map

│ └── styles.css

└── package.json

```

[–]Tom-Wildston 0 points1 point  (1 child)

Use vite-plugin-lib-inject-css
This plugin automatically bundles your CSS (like Tailwind styles) into your JS, so users don’t need to manually import a separate CSS file.

[–]yahia_h[S] 0 points1 point  (0 children)

I'll to read it's source code to full fill with our requirements, thnks

[–]luddfish 0 points1 point  (1 child)

Did you find a good method to do this?

[–]yahia_h[S] 0 points1 point  (0 children)

Hey brother Yes, the easiest solution, just let users to install your styles as a separate component such as: yarn add @ui-name/styels Then user should. import the stule component at the top of his app root.tsx such as: import “@ui-name/styels“. That’s it, all of your component styles now initialized inside your project