Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import external sass or scss variables with Svelte and Vite

Tags:

sass

svelte

vite

I've created a big sass stylesheet with all sorts of colors. Following vite's guide for sass, I got sass working in my components. Now I'd like to use these external variables in my Svelte components' stylesheets as well.

So far I've tried:

@use "./test.sass" // along with "./test"
p {
  color: $testColor
}

As well as

@import url("./test.sass") // along with "./test"
// ... same as above

It gives me an error Error: Undefined variable. And my variable is defined properly in test.sass

like image 756
Pete Avatar asked Nov 16 '25 12:11

Pete


1 Answers

@use wraps imported variables in a namespace, so instead of $testColor you have to explicitly state that these variables come from a module.

@use "./test.sass"
p {
  color: test.$testColor
}

or

@use "./test.sass" as *
p {
 color: $testColor
}
like image 122
JUBEI Avatar answered Nov 18 '25 19:11

JUBEI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!