flowbite-react icon indicating copy to clipboard operation
flowbite-react copied to clipboard

Support for workspaces with flowbite.content()

Open sughodke opened this issue 1 year ago • 4 comments

As the below line from this very repo shows, flowbite.content() returns a path assuming you are running flowbite in a standalone repo. But if you are using flowbite in monorepo, this assumption is not valid and the path returned by flowbite.content() is incorrect. The build (via npm run build) works as expected, but the resultant CSS artifacts don't contain all the CSS.

https://github.com/themesberg/flowbite-react/blob/bed3c41eb3291430db424b2e37233659507e1581/apps/web/tailwind.config.cjs#L11

I propose within flowbite.content() we use require.resolve() to correctly find the node_modules directory to avoid this guessing.

import path from 'path';

export function content( ... ) {
  const flowbiteDir = path.dirname(
    require.resolve('flowbite-react/package.json', { paths: [__dirname] })
  );
  
   return path.join(flowbiteDir, 'dist/esm/**/*.mjs');
}

sughodke avatar Oct 04 '24 12:10 sughodke

The below line u are referring to is exactly configured to be used within a monorepo (in this very monorepo structure) where node_modules are to be found 2 levels out from the directory its being used (apps/web/*).

https://github.com/themesberg/flowbite-react/blob/bed3c41eb3291430db424b2e37233659507e1581/apps/web/tailwind.config.cjs#L11

We'll think of a better API in the future for configuring paths for monorepo structures.

SutuSebastian avatar Oct 04 '24 13:10 SutuSebastian

node_modules are to be found 2 levels out from the directory

Why not have it auto-configured? Avoid shooting yourself in the foot, and guessing where the right directory is.

We'll think of a better API in the future for configuring paths for monorepo structures.

Eager to learn more, what did you have in mind?

sughodke avatar Oct 04 '24 22:10 sughodke

@sughodke u can't really have it "auto-configured" due to the vast ways of using and configuring monorepo's, it's almost impossible to auto detect where the package is installed, thats why we're considering to pre-compile and extract all classNames used in the package (per component too), and feed those to tailwind.config.js, but keep in mind this is experimental for now and it might change.

Also, this is why flowbite.content() accepts an options param which has base as an overridable, giving u access to hoist in the correct directory the node_modules path

SutuSebastian avatar Oct 08 '24 07:10 SutuSebastian

Why not have it auto-configured? Avoid shooting yourself in the foot, and guessing where the right directory is.

That's the point, we're not, we know exactly where the packages are being installed, since we configured the monorepo, so there's no "guessing".

SutuSebastian avatar Oct 08 '24 07:10 SutuSebastian

Solved by the #1498

SutuSebastian avatar Mar 26 '25 10:03 SutuSebastian