Sharing Tailwind components in a monorepo
See original GitHub issueFirst of all thanks for the great tool. This is a report that something is not working right, but also a question on how you recommend to do this kind of thing. There are many tools at play here so hopefully you can point me in the right direction.
Describe the problem:
I have a monorepo like this:
packages/
app-1/
app-2/
ui/
My apps are a combination of create-react-app and Next.js, but for now I just want to get my demo working with two create-react-app applications.
Ideally I’d be able to have a ui/common.css file that I can import into my applications:
@import '@tailwind-test/ui/common.css';
/* ./src/index.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
but that doesn’t work. Additionally I’d like to be able to import components (e.g. ui/button.tsx) and have the Tailwind classes still autogenerated. ie. ui/button.tsx uses bg-blue-500 and that CSS class is still generated in the application.
Link to a minimal reproduction:
https://github.com/AlexBHarley/tailwind-shared-components-demo.
Right now I can’t even get @import to work so I’m copy pasting my common.css file into the tailwind.css file of each of my three applications.
To run:
yarnyarn lerna bootstrapyarn lerna run start --stream
Issue Analytics
- State:
- Created 3 years ago
- Reactions:21
- Comments:9
Top Related StackOverflow Question
One Solution is to elaborate all file paths which uses tailwind in the tailwind.config.js
for example, if package structure is like this
and if you want to import component from your app project /app/tailwind.config.js should be somewhat like this :
I hope this might help someone.
@Manubi I didn’t find any way other than installing tailwind separately in each project that uses UI package, but having only the code in the UI package + tailwind configuration file. So would be something like this:
And then
landing-pagewould have tailwindcss in it, but it would use the config from ui. This is useful when there’s, let’s say another landing page that is supposed to use the same config as the first landing page.The drawback is that we’d have to install tailwind package in both of the landing pages (but not in the UI!). Your ui tailwindcss config file would have the base and the tailwindcss configs in the other packages can be defined as:
And then import the components from the ui as:
This worked perfectly for me.