Scss and tailwind on nuxt
Hi guys, i have troubles settings scss.
In the config i have, scss works but create lot of files (2 per .scss file), i would like all scss file be compiled on one single file.
Also i addes tailwind and i would like to make it work too.
If you could help me to understand, thank you.
My nuxt config
2 Replies
Hi @Hugo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To address your issues with SCSS and Tailwind in Nuxt, let's break down the problem and provide some solutions:
1. SCSS Compilation:
To compile all your SCSS files into a single file, you need to adjust your SCSS setup. Instead of having Nuxt process each SCSS file individually, you should create a main SCSS file that imports all other SCSS files.
Create a main SCSS file (e.g.,
~/assets/scss/main.scss
) and import all other SCSS files there:
Then, in your nuxt.config.js
, only include this main SCSS file:
This approach will result in a single compiled CSS file.
2. Tailwind Integration:
Your configuration already includes Tailwind CSS, which is good. The @nuxtjs/tailwindcss
module is added to the modules
array, and you've included the Tailwind CSS file in the css
array.
To ensure Tailwind works correctly with SCSS, make sure your tailwind.config.js
file is properly set up. Here's a basic example:
3. PostCSS Configuration:
Your PostCSS configuration looks good. It includes the necessary plugins for Tailwind and SCSS to work together.
4. Vite Configuration:
Your Vite configuration for SCSS looks correct. However, you might want to add the additionalData
option if you need to inject global SCSS variables or mixins:
This setup will allow you to use SCSS variables and mixins across your components without explicitly importing them Docs > Getting-started > Styling > Using Preprocessors (https://nuxt.com/docs/getting-started/styling#using-preprocessors).
With these adjustments, your SCSS should compile into a single file, and Tailwind should work correctly alongside SCSS. If you're still experiencing issues, make sure all your dependencies are up to date and that you're using compatible versions of Nuxt, Tailwind, and the related modules.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@122807566475591680> Kapa.ai is still learning and improving, please let me know how I did by reacting below.