Nuxt 3 first Release Candidate will be launched very soon, so I am starting a fresh new project with Nuxt 3. I am already facing an usual issue, and I was about to ask how to solve it. But I managed to do it by myself, so I am making a Self Answered question, in order to help people that might face the same issue in the futur.
How to use global Sass (or Scss) variables in my vue components ? I saw on other posts that we can use the @nuxtjs/style-resources package, but it seems like a Nuxt 2 package. And I think there might be a better way to do it in Nuxt 3 without adding dependencies like style-resources ?
What I mean by "global variable" is a SASS variable is that I want to be able to use the SASS variable in any of my Vue components, without having to include SASS files.
What I want
(Given that I already installed the sass package)
// @/assets/style/main.sass
$grey-bg: #CCC
$light-blue: #c6d8f5
<!-- app.vue -->
<template>
<div>
<NuxtWelcome />
</div>
</template>
<style lang="sass">
body
background-color: $grey-bg
color: $light-blue
</style>
What I already tried
I tried to include my sass file in the Nuxt config CSS property like this :
// nuxt.config.ts
import { defineNuxtConfig } from "nuxt3"
export default defineNuxtConfig({
css: ["@/assets/style/global.sass"]
})
And it work in the way that the style in my global.sass file will be applied in my entire application. But it does not work in the way that if I refer to a variable in my SASS file from a Vue Component, the build fails with this error :
Plugin: vite:css. Error: Undefined variable.