#How to make sass app with NuxtJS3?

3 messages · Page 1 of 1 (latest)

loud hornetBOT
#

Hi @verbal idol. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To create a Sass app with Nuxt 3, you'll need to follow these steps:

  1. Install Sass:
    First, install the Sass preprocessor:
npm install -D sass
  1. Create Sass files:
    Place your Sass files in the assets directory. For example, you might have a main Sass file at assets/scss/main.scss.

  2. Configure Nuxt:
    In your nuxt.config.ts file, add the following configuration:

export default defineNuxtConfig({
  css: ['~/assets/scss/main.scss'],
  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "~/assets/scss/_variables.scss" as *;'
        }
      }
    }
  }
})

This configuration does two things:

  • It includes your main Sass file globally.
  • It allows you to use Sass variables and mixins across your components without explicitly importing them each time.

Nuxt Documentation (https://nuxt.com/docs/getting-started/styling#using-preprocessors)

  1. Structure:
    A typical structure for a Nuxt 3 project with Sass might look like this:
your-nuxt-project/
├── assets/
│   └── scss/
│       ├── _variables.scss
│       ├── _mixins.scss
│       └── main.scss
├── components/
├── pages/
├── public/
├── nuxt.config.ts
└── package.json
  1. Using Sass in components:
    You can use Sass directly in your Vue components:
<template>
  <div class="example">Hello Nuxt with Sass!</div>
</template>

<style lang="scss">
.example {
  color: $primary-color; // Using a variable from _variables.scss
}
</style>

Remember, Nuxt 3 uses Vite by default, which handles Sass compilation for you. There's no need for additional watchers or compilers.

Stack Overflow - Nuxt 3 + SASS (https://stackoverflow.com/questions/77544274)

#

By following these steps, you'll have a Nuxt 3 application set up with Sass support, allowing you to use Sass features throughout your project.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: