I trying do import globally an variables.scss file
my vue.config.js like the following:
module.exports = {
css: {
loaderOptions: {
scss: {
additionalData: `@import "@/styles/variables.scss";`
},
}
}
}
variables.scss
$dark-bg: #1C2537;
and vue file where i try use it
<script setup>
// Component logic
</script>
<template>
<!-- Template -->
</template>
<style lang="scss">
@import "@/styles/variables.scss"; // if i add this all works
.left-menu {
background-color: $dark-bg;
}
</style>
when i directly import variables.scss in vue file all work good but global import not works
if any idea what problem is?
i use: "sass": "^1.69.5", "sass-loader": "7.3.1", "vue": "^3.2.26",
i expect my variables from variables.scss works globally in all vue files
I've quite similar configuration but the only thing that differs from yours is the
scssproperty which is `sass :Syntax for sass-loader v9 and above :
In my
.vuefile I can do then the following with no errors :Since, according to documentation,
sassoptions also applies toscssoptions, maybe you could give it a try ?My declared version of vue / sass and sass-loader in
package.json:Important note in documentation : this option is named as
prependDatain sass-loader v8EDIT After digging more since we have some differences in
sass-loaderversions, I found that you should use thedataoption, as suggested by Alex in the commentsSee changelog v8 where they say that
And then see changelog v9 where they say that
So here is correct syntax for v8 sass-loader (working with scss or sass loaderOptions) :
For v7 and below :
And for v9 and above