Install sass if It's Not Installed
If sass is missing from your project, install it using:
npm install sass --save-dev
Fix the Path in vite.config.js
In vite.config.js, change the additionalData option to use the alias @ instead of ./src/...:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/scss/_variables.scss" as *;`
}
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
})
Restart the Vite Development Server
npm run dev
Key Points:
✔ Use @use "@/assets/scss/_variables.scss" as *; instead of @import, since @import is deprecated in Dart Sass 3.0.0+.
✔ Ensure the path starts with @/ instead of ./src/, which might not be resolved correctly by Vite.