Skip to content

Instantly share code, notes, and snippets.

@jaames
Created January 3, 2022 15:14
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jaames/76130b03465e7e7a9dd0405fdca05888 to your computer and use it in GitHub Desktop.
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
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";`
}
}
}
}
};
@PierBover
Copy link

Thanks!

@tocky
Copy link

tocky commented Apr 11, 2023

This snippet helped me, thanks!

@Bartunek
Copy link

Bartunek commented Jul 8, 2023

God bless you! Exactly what I was looking for! 🥇

@flaviort
Copy link

You, my friend, are a true scholar!!!!

@adleviton
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment