Last active
October 5, 2024 17:55
-
-
Save jaames/76130b03465e7e7a9dd0405fdca05888 to your computer and use it in GitHub Desktop.
Injecting global SCSS variables in Astro (https://astro.build), using additionalData and a path alias
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note for typescript users: you will need to install node.js types into your project with `npm i -D @types/node` | |
import { fileURLToPath } from 'url'; | |
import path, { dirname } from 'path'; | |
const __filename = fileURLToPath(import.meta.url); | |
const __dirname = dirname(__filename); | |
export default { | |
// all the usual config goes here... | |
vite: { | |
resolve: { | |
alias: { | |
'@/': `${path.resolve(__dirname, 'src')}/` | |
} | |
}, | |
css: { | |
preprocessorOptions: { | |
scss: { | |
// path to your scss variables | |
additionalData: `@import "@/styles/vars.scss";` | |
} | |
} | |
} | |
} | |
}; |
This snippet helped me, thanks!
God bless you! Exactly what I was looking for! 🥇
You, my friend, are a true scholar!!!!
👍
great thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!