I have tried to set up some global Scss in my Gatsby application, but it looks like after doing this i am seeing some odd behaviour in dev tools:
You can see that my global styles are appearing and being overwritten multiple times.
It is a Gatsby app so i am using sass-loader
and the default dart-sass
.
Here is how i have configure my gatsby-config.js
file to allow me to use these global styles based on this stackoverflow post: https://stackoverflow.com/a/65904094/12119984
module.exports = {
plugins: [
...
{
resolve: `gatsby-plugin-sass`,
options: {
additionalData: `@use 'main' as *;`,
//allow mixins, variables etc to be accessible globally
sassOptions: {
includePaths: [`${__dirname}/src/styles/sass`],
// data: `@import "main.scss";`,
},
},
}...
I the use @forward
along with @extend
to get it all working in my module.scss files. My folder structure looks like this:
My global styles are in base.scss
and I import them into main.scss
using @forward
:
@forward "base";
@forward "layout";
@forward "components";
As an exmaple, here is my index.module.scss
file where i then use these global styles:
.sectionHome {
...
h1 {
background-color: $color-secondary;
@extend .uMarginBottomLarge;
@extend .headingPrimary;
}
}
It seems like a reasonable approach to me to use some global styles but to extend them into local sccs module classes, so can anyone explain to why these global styles are being applied several times?