question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gatsby-plugin-sass] Little improvements

See original GitHub issue

Summary

  1. Use the node-sass-chokidar lib instead node-sass to increase boost performance.
  2. Add sass-resources-loader to make common resources (variables, mixins, etc) available in all Sass/Scss files in the project if you need.

Basic example

plugins: [
  {
    resolve: `gatsby-plugin-sass`,
    options: {
      ...
      resources: ['./path/to/vars.scss', './path/to/mixins.scss']
    },
  },
];

Check the documentation for more examples.

Motivation

  1. As a lab, I changed the package in my application during developing mode, and it decreased the RAM consumed by 15%.
  2. The includePaths param doesn’t work to make my variables or mixins available on my .scss files.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
ixrockcommented, Sep 19, 2018

To auto-include some sass vars/mixins/etc. into your component *.scss files you simply can pass data option for node-sass with @import. e.g: if you have common file in src/components/vars.scss, then use in your plugins declaration:

    {
      resolve: `gatsby-plugin-sass`,
      options: {
        data: '@import "vars.scss";',
        includePaths: [
          'src/components',
        ],
      },
    }
6reactions
chengyincommented, Aug 6, 2018

Seems like the custom webpack config merging can combine gatsby-plugin-sass and custom configs, so personally I have this gatsby-node.js file to append sass-resources-loader:

exports.onCreateWebpackConfig = ({
  actions,
  stage,
  rules,
  plugins,
  loaders,
}) => {
  const sassRuleModules = {
    test: /\.module\.s(a|c)ss$/,
    use: [
      {
        loader: 'sass-resources-loader',
        options: {
          resources: [
            'src/styles/_variables.scss',
            'src/styles/_mixins.scss',
            'src/styles/_typography.scss',
          ],
        },
      },
    ],
  };

  actions.setWebpackConfig({
    module: {
      rules: [sassRuleModules],
    },
  });
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-plugin-sass
gatsby -plugin-sass. Provides drop-in support for Sass/SCSS stylesheets. Install. npm install sass gatsby-plugin-sass. How to use. Include the plugin in your ...
Read more >
Get set up with a Gatsby, TypeScript, and Sass configuration
Until these projects don't evolve a little bit I'm going to do small modifications to the basic Gatsby. These also has the benefit...
Read more >
Learning GatsbyJS. A little attempt to learn to build a…
Install and config sass with Gatsby npm install sass gatsby-plugin-sass. 3. Include the plugin in your gatsby-config.js file. plugins: [
Read more >
Creating a Gatsby Site with WordPress Data - CSS-Tricks
Install the WPGraphQL and WPGraphiQL plugins. Let's start by installing a couple of plugins in WordPress. We'll use WPGraphQL to enable GraphQL ...
Read more >
State Management in Gatsby using the wrapRootElement Hook
If you have any suggestions for improvements, please let us know by clicking ... I'll add Sass support with node-sass and gatsby-plugin-sass ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found