nuxt-modules / tailwindcss

Tailwind CSS module for Nuxt
https://tailwindcss.nuxtjs.org
MIT License
1.59k stars 179 forks source link

Nuxt not reading the value of tailwind config #845

Closed fachryadhitya closed 1 week ago

fachryadhitya commented 1 week ago

Environment

Reproduction

No response

Describe the bug

Hello there 👋

First of all, thanks for making the integration of Tailwind and Nuxt so easy! I love this very much.

I have a question: I wanted to force my app to just use light mode. After setting the colorMode and preference to light, I can see the correct class=light value in the HTML head, but Tailwind still seems to be using the system preference when reading the class name, even though I have set the darkMode in the config to be class-based.

CleanShot 2024-05-05 at 22 52 33@2x

CleanShot 2024-05-05 at 22 47 54@2x

Then, I tried to check if Nuxt is correctly reading my config by creating a new custom color. Upon testing, I found that the color is not recognizable, which indicates that Nuxt is not reading my Tailwind configuration.

CleanShot 2024-05-05 at 22 50 28@2x

CleanShot 2024-05-05 at 22 51 04@2x

My question is: what might I have set incorrectly for Nuxt to not read my config correctly?

PS: I'm not changing the Tailwind config path in nuxt.config.js. I'm using the default file, which is tailwind.config.js.

Here's my full tailwind config

const animate = require("tailwindcss-animate");
const { blackA, green, grass, mauve } = require("@radix-ui/colors");

/** @type {import('tailwindcss').Config} */
module.exports = {
  darkMode: "class",
  content: [
    "./pages/**/*.{ts,tsx,vue}",
    "./components/**/*.{ts,tsx,vue}",
    "./app/**/*.{ts,tsx,vue}",
    "./src/**/*.{ts,tsx,vue}",
  ],
  theme: {
    container: {
      center: true,
      padding: "2rem",
      screens: {
        "2xl": "1400px",
      },
    },
    extend: {
      colors: {
        "green-primary": "#00A878",
        primary: "#3177FF",
        secondary: "#CCDDFF",
      },
      keyframes: {
        "accordion-down": {
          from: { height: 0 },
          to: { height: "var(--radix-accordion-content-height)" },
        },
        "accordion-up": {
          from: { height: "var(--radix-accordion-content-height)" },
          to: { height: 0 },
        },
      },
      animation: {
        "accordion-down": "accordion-down 0.2s ease-out",
        "accordion-up": "accordion-up 0.2s ease-out",
      },
    },
  },
  plugins: [animate],
};

Thank you very much!

Additional context

No response

Logs

No response

ineshbose commented 1 week ago

Could you share a screenshot of your Nuxt config and directory tree please?

fachryadhitya commented 1 week ago

Sure!

Nuxt Config

import { pwa } from "./config/pwa";
import { appDescription } from "./constants/index";

export default defineNuxtConfig({
  modules: [
    "@nuxtjs/tailwindcss",
    "@vueuse/nuxt",
    "@pinia/nuxt",
    "@nuxtjs/color-mode",
    "@vite-pwa/nuxt",
    "nuxt-module-eslint-config",
    "shadcn-nuxt",
    "nuxt-tiptap-editor",
  ],
  shadcn: {
    /**
     * Prefix for all the imported component
     */
    prefix: "",
    /**
     * Directory that the component lives in.
     * @default "./components/ui"
     */
    componentDir: "./components/ui",
  },
  tiptap: {
    prefix: "Tiptap", //prefix for Tiptap imports, composables not included
  },
  experimental: {
    // when using generate, payload js assets included in sw precache manifest
    // but missing on offline, disabling extraction it until fixed
    payloadExtraction: false,
    renderJsonPayloads: true,
    typedPages: true,
  },

  colorMode: {
    // classSuffix: "light",
    preference: "light",
  },

  nitro: {
    esbuild: {
      options: {
        target: "esnext",
      },
    },
    prerender: {
      crawlLinks: false,
      routes: ["/"],
      ignore: ["/hi"],
    },
  },

  app: {
    head: {
      viewport: "width=device-width,initial-scale=1",
      link: [
        { rel: "icon", href: "/favicon.ico", sizes: "any" },
        { rel: "icon", type: "image/svg+xml", href: "/nuxt.svg" },
        { rel: "apple-touch-icon", href: "/apple-touch-icon.png" },
      ],
      meta: [
        { name: "viewport", content: "width=device-width, initial-scale=1" },
        { name: "description", content: appDescription },
        {
          name: "apple-mobile-web-app-status-bar-style",
          content: "black-translucent",
        },
        {
          name: "theme-color",
          content: "#ffffff",
        },
        {
          name: "color-scheme",
          content: "light dark",
        },

        // {
        //   name: "theme-color",
        //   media: "(prefers-color-scheme: dark)",
        //   content: "#222222",
        // },
      ],
    },
  },

  // pwa,

  devtools: {
    enabled: true,
  },

  eslintConfig: {
    setup: false,
  },
});

CleanShot 2024-05-05 at 23 01 39@2x

ineshbose commented 1 week ago

Hmm.. do you have an assets/css/tailwind.css you could share contents of?

fachryadhitya commented 1 week ago

weird right.. oh it's actually just for testing purpose; I can safely delete it and it still wont read my nuxt config

the content is just this

@tailwind base;
@tailwind components;
@tailwind utilities;
ineshbose commented 1 week ago

Sorry - I'll triage this ASAP. Meanwhile, if you can help me help you faster, a web reproduction would be amazing!

https://stackblitz.com/github/nuxt-modules/tailwindcss/tree/docs-examples/examples/basic-usage

fachryadhitya commented 1 week ago

sorry its working now! found the issues in nuxt config, importing module that's somehow problematic. Will close this. Thank you!