DEV Community

Jordi
Jordi

Posted on • Edited on

5 1

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

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay