Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tailwind module integration #237

Merged
merged 9 commits into from
Apr 11, 2024
7 changes: 5 additions & 2 deletions docs/content/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Props:

## TailwindCSS

Tailwind v2 introduced [dark mode](https://tailwindcss.com/docs/dark-mode), in order to work with `@nuxtjs/color-mode`, you need to set `darkMode: 'class'` in your `tailwind.config.js`:
This module will work out of the box with [@nuxtjs/tailwindcss](https://github.com/nuxt-modules/tailwindcss) (registered after this module). Tailwind v2 introduced [dark mode](https://tailwindcss.com/docs/dark-mode), in order to work with `@nuxtjs/color-mode`, you need to set `darkMode: 'class'` in your `tailwind.config.js`:

```js [tailwind.config.js]
module.exports = {
Expand All @@ -186,7 +186,10 @@ Then in your `nuxt.config.ts`, set the `classSuffix` option to an empty string:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@nuxtjs/color-mode'],
modules: [
'@nuxtjs/color-mode',
// '@nuxtjs/tailwindcss' // specify after
danielroe marked this conversation as resolved.
Show resolved Hide resolved
],
colorMode: {
classSuffix: ''
}
Expand Down
5 changes: 5 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export default defineNuxtModule({
config.plugins.push(resolve(runtimeDir, 'nitro-plugin'))
})

nuxt.hook('tailwindcss:config', (tailwindConfig) => {
options.classSuffix = ''
ineshbose marked this conversation as resolved.
Show resolved Hide resolved
tailwindConfig.darkMode = 'class'
})

if (!isNuxt2()) {
return
}
Expand Down