for (const file of files) { const contents = await fs.readFile(path.resolve(cwd, file), "utf8") // Assume that if the file contains `@tailwind base` it's the main css file. if (contents.includes("@tailwind base")) { return file } }
There is a check contents.includes(“@tailwind base”) which is based on an assumption described in a comment.
Finding the main css file with tailwind base classes based on an assumption that the content of file includes @tailwind base is clever.
Again, this getTailwindFile also uses fg.glob to get all the files in a given cwd to find the file that contains @tailwind base
I don’t know if I will ever use such an implementation but for now I know that such a thing is possible with fast-glob. Comes handy when you are building a CLI like package.
Want to learn how to build shadcn-ui/ui from scratch? Check outbuild-from-scratch
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.