I've been at this for a couple of days now and still can't seem to get this working. I'm trying to get the whole dark mode going with Tailwind CSS in Nuxt.js.
I think it may be an issue with the CSS setup and not the TypeScript side as I have a toggle that switches the <hmtl></html> class to light and dark.
As a reference, I've been trying to copy Fayazara's work which you can find here.
Env:
- Windows 10 Pro
- Node 14.15.4
- NPM 6.14.10
- Nuxt.js 2.14.12
- TailwindCSS 2.0.2
Here are some of the config files:
nuxt.config.js:
export default {
head: {
// meta stuff
},
purgeCSS: {
whitelist: ['dark-mode'],
},
components: true,
buildModules: [
'@nuxt/typescript-build',
'@nuxtjs/tailwindcss',
'@nuxtjs/color-mode',
],
colorMode: {
classSuffix: ""
},
...
...
}
tailwind.config.js:
module.exports = {
theme: {
darkSelector: '.dark-mode',
},
variants: {
backgroundColor: ['dark', 'dark-hover', 'dark-group-hover', 'dark-even', 'dark-odd', 'hover', 'responsive'],
borderColor: ['dark', 'dark-focus', 'dark-focus-within', 'hover', 'responsive'],
textColor: ['dark', 'dark-hover', 'dark-active', 'hover', 'responsive']
},
plugins: [
require('tailwindcss-dark-mode')()
]
}
~/assets/css/tailwind.css:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
I have this in my settings page <p class="bg-blue-500 dark:bg-red-500">Settings</p> which stays blue even with the toggle
I uploaded my project to GitHub for all the other files
Thanks to anyone that helps :)