Multiple tailwind configurations for one website #3587
-
Hey team 👋 Is there a way to have two different tailwind configs apply for different pages in Next.js or is there a better way to approach this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
I think you're only truly integrated option will be digging into customizing the webpack config and manually configuring two instances of postcss-loader that look at different sources and have an inline configuration so you can pass in different options unfortunately. Another option is to compile your CSS out of process (using the Tailwind CLI or similar) and just compile those files using dedicated scripts. You can have a |
Beta Was this translation helpful? Give feedback.
-
also interested in this! did you come up with a solution? I've sucessfully bundled multiple tailwind configs, however because I am using the same "class" names on my tailwind config, they collide. ie:
In my case, BOTH configs are bundled into a css file, and only the last one is applied (naturally) |
Beta Was this translation helpful? Give feedback.
-
We are also trying to get multiple-configs working. Our setup has vite and postcss transpiling everything. If I use the config directive pointing to 2 different config files it fails with an error: My assumption is some issue with relative pathing making it unable to find the config as defined.
Does anyone have a working setup with the css entry somewhat deeply nested compared to the config? postcss.config.js
|
Beta Was this translation helpful? Give feedback.
-
You can do the following if you want to change the config for site based on // tailwind.config.js
import { XXX_TAILWIND_CONFIG } from './tailwind.yyy.config';
import { YYY_TAILWIND_CONFIG } from './tailwind.yyy.config';
module.exports = process.env.NEXT_PUBLIC_BRAND_NAME === 'XXX' ? XXX_TAILWIND_CONFIG : YYY_TAILWIND_CONFIG; Your If you're only interested in entry per file then the easiest is to use the built in @config directive. |
Beta Was this translation helpful? Give feedback.
I think you're only truly integrated option will be digging into customizing the webpack config and manually configuring two instances of postcss-loader that look at different sources and have an inline configuration so you can pass in different options unfortunately.
Another option is to compile your CSS out of process (using the Tailwind CLI or similar) and just compile those files using dedicated scripts. You can have a
tailwind.app.config.js
file and atailwind.marketing.config.js
file and just pass those names to the Tailwind CLI on the command line.