DEV Community

Jordi Enric
Jordi Enric

Posted on • Updated on

How to add a global SCSS file to your Gridsome project

I love Gridsome for it's easy setup, themes and over all developer experience. One thing I decided to do as soon as I set up my project was to add a global SCSS/SASS file for my global styles. This was I did not have to write global styles on my components which is not optimal if you want to keep a good separation of concerns. Here's how to do it:

Tell gridsome to load your scss in gridsome.config.js

Go to your gridsome.config.js file and write this:

module.exports = {
  css: {
    loaderOptions: {
      scss: {
        prependData: '@import "./src/assets/style/index.scss";'

Enter fullscreen mode Exit fullscreen mode

In case you are using sass instead of scss remember to change "scss" to "sass" below loaderOptions.

Restart your server and that's it, you will be able to write use your scss variables in your components.

Have a good day ✌✌

Find me on Twitter

Top comments (0)