You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
I have used your monorepo setup from quite a long time ago and I loved how you use a script to generate index.ts on the root of the ui component folder. For me, it makes every easier and made the code imports cleaner, which I can do something like this:
import{Button,ScrollArea,Separator,Sheet,SheetContent,SheetHeader,SheetTitle,SheetTrigger,// or any other shadcn components}from'@ui/index'
Recently I'm stared creating a new monorepo and I saw things have changed a bit. (And I loved the improvements ✨)
However, I missed having the index.ts for all component import shortcut. I'm not sure if it is because the old scripts were having confilcts with the use-toast.ts and now the sonnar.tsx component, so I've modified the generateIndex.mts like so which solves issues mentioned above.
//generateIndex.mtsimportfsfrom"fs";importpathfrom"path";import{fileURLToPath}from"url";// Get the current file's directory pathconst__filename=fileURLToPath(import.meta.url);const__dirname=path.dirname(__filename);constcomponentsPath=path.join(__dirname,"../components/ui");constindexFilePath=path.join(componentsPath,"../../index.ts");// Generate the index.tsx file by looping through all the files in the components folderconstcomponentFiles=fs.readdirSync(componentsPath);constexportStatements=componentFiles.map((file)=>{// ignore use-toast.tsxif(file==="use-toast.ts")return"";if(file==="sonner.tsx")return"export { Toaster as Sonner } from './components/ui/sonner';";constcomponentName=path.basename(file,".tsx");return`export * from './components/ui/${componentName}';`;});constbanner=`//! This file is auto-generated by the generateIndex.mts script. Do not edit this file directly.\n\n`;constindexFileContent=banner+exportStatements.join("\n")+"\n";fs.writeFileSync(indexFilePath,indexFileContent,"utf8");console.log("\x1b[32m%s\x1b[0m","index.tsx file generated successfully.");
The only thing that will be different for the import paths from shadcn doc is the Sonner component, which now becomes:
import { Sonner } from '@ui/index'
It's isn't an issue really, just wanted to share this in case anyone needs it!
The text was updated successfully, but these errors were encountered:
First of all, great repo!
I have used your monorepo setup from quite a long time ago and I loved how you use a script to generate index.ts on the root of the ui component folder. For me, it makes every easier and made the code imports cleaner, which I can do something like this:
Recently I'm stared creating a new monorepo and I saw things have changed a bit. (And I loved the improvements ✨)
However, I missed having the
index.ts
for all component import shortcut. I'm not sure if it is because the old scripts were having confilcts with theuse-toast.ts
and now thesonnar.tsx
component, so I've modified thegenerateIndex.mts
like so which solves issues mentioned above.The only thing that will be different for the import paths from shadcn doc is the
Sonner
component, which now becomes:It's isn't an issue really, just wanted to share this in case anyone needs it!
The text was updated successfully, but these errors were encountered: