rayyamhk / vite-react-component-library-starter

Starter template for React component library
MIT License
28 stars 2 forks source link

Tailwind CSS not applied to components without manual CSS import #1

Open md-moijul opened 5 months ago

md-moijul commented 5 months ago

Description

When consuming components from vite-react-component-library-starter, the Tailwind CSS styles are not automatically applied to the components. To get the styles working, it is currently necessary to manually import the CSS file along with the component. Ideally, importing a component should automatically include its styling without needing an additional import statement for the CSS.

image image

Steps to Reproduce

  1. Clone the vite-react-component-library-starter repository:

git clone git@github.com:rayyamhk/vite-react-component-library-starter.git

  1. Install dependencies and build the library:

npm install && npm run build:lib

  1. Link the library for local development:

npm link

  1. Create a new project and link vite-react-component-library-starter to it:

npm link vite-react-component-library-starter

  1. Use a component from the library without importing the CSS file:
    
    import { Button } from 'vite-react-component-library-starter';
    // import 'vite-react-component-library-starter/css'; 

export default function App() { return ( <>

hello world

        <Button>Click Me!</Button>
    </>
);

}



## Expected Behavior
The Button component should have Tailwind CSS styles applied without the need for manually importing the CSS file.

## Actual Behavior
The Tailwind CSS styles are not applied to the Button component unless the CSS file is manually imported

## Possible Solution ???
Is there a recommended approach or workaround for this issue? Ideally, importing a component should automatically apply its styling.
mnlfischer commented 4 months ago

This is an issue with Tailwind. There is no option in Tailwind to create component based css files otherwise Tailwind needs to merge all files to check if there are redundant classes and if so, which component should be now implement the styles? If both, the idea of Tailwind wont work because you would have styles twice defined.