Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-plugin-sass prevents configuration of CSS Loader #29955

Closed
Titou325 opened this issue Mar 3, 2021 · 7 comments · Fixed by #29986 or #30112
Closed

gatsby-plugin-sass prevents configuration of CSS Loader #29955

Titou325 opened this issue Mar 3, 2021 · 7 comments · Fixed by #29986 or #30112
Assignees
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Titou325
Copy link

Titou325 commented Mar 3, 2021

Description

When setting the following options to gatsby-config.js:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-sass`,
      options: {
        cssLoaderOptions: {
          modules: {
            exportLocalsConvention: 'camelCaseOnly'
          }
        }
      }
    }
  ]
}

We expect the exports of css-loader to be camelCaseOnly and not dashesOnly (default).

Steps to reproduce

Very straightforward, just place this in a Gatsby SASS project.

Expected result

The webpack configuration should be modified accordingly and the exported values should be in camel case.

Actual result

Nothing changes. After investigation, it seems that the culprit is in gatsby-plugin-sass/gatsby-node.js where there is the following:

const sassRuleModules = {
    test: sassRuleModulesTest || /\.module\.s(a|c)ss$/,
    use: [!isSSR && loaders.miniCssExtract({
      modules: true
    }), loaders.css({
      importLoaders: 2,
      ...cssLoaderOptions,
      modules: true
    }), loaders.postcss({
      plugins: postCssPlugins
    })].filter(Boolean)
  };

This causes the modules option to be overwritten even if it was provided. There should be a check to see if there is already a modules option to prevent overwriting.

Environment

  System:
    OS: Windows 10 10.0.19041
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 15.3.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.9 - ~\AppData\Roaming\npm\npm.CMD
  Languages:
    Python: 3.6.4
  Browsers:
    Chrome: 88.0.4324.190
    Edge: Spartan (44.19041.423.0), Chromium (88.0.705.81)
  npmPackages:
    gatsby: ^3.0.0 => 3.0.0
    gatsby-plugin-mdx: ^2.0.0 => 2.0.0
    gatsby-plugin-sass: ^4.0.0 => 4.0.0
    gatsby-source-filesystem: ^3.0.0 => 3.0.0
    gatsby-telemetry: ^2.0.0 => 2.0.0
  npmGlobalPackages:
    undefined: 0.1.0
@Titou325 Titou325 added the type: bug An issue or pull request relating to a bug in Gatsby label Mar 3, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 3, 2021
@juanbiberretta
Copy link

+1! I opened up the issues tab to report this very same thing!

@LekoArts
Copy link
Contributor

LekoArts commented Mar 3, 2021

Hi, thanks for the issue!

Just to make sure: Did this only occur with gatsby@3.0.0 and gatsby-plugin-sass@4.0.0 or already with gatsby@2.32.0 and gatsby-plugin-sass@3.0.0?

@LekoArts LekoArts added topic: sass and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 3, 2021
@Titou325
Copy link
Author

Titou325 commented Mar 3, 2021

Hello!

I believe it might have existed before, I am only impacted now since we are moving to Gatsby 3.0.0 and refactoring our imports. We did not use gatsby-plugin-sass before, hence I can't be sure of the behavior but from the source code I believe it did not before Gatsby V3 as it was still using css-loader@^1.0.1, which has now been upgraded to ^5. (As a side note the documentation at https://www.gatsbyjs.com/plugins/gatsby-plugin-sass/ is wrong for V3 as css-loader has been upgraded).

I believe the overwrite occurs because it used to be a boolean only option, but it can now be an object. I might be mistaken though.

If I can provide any further help, feel free to reach out,

Thanks and have a nice day

@LekoArts
Copy link
Contributor

LekoArts commented Mar 3, 2021

Thanks for the info and the note that the README will need an update. We'll look into both things :)

@juanbiberretta
Copy link

@LekoArts Thanks for the quick turnaround on this! Much appreciated

@juanbiberretta
Copy link

@LekoArts Just for my own understanding but when/how will the hotfix make it out to users? Sorry not incredibly well versed in open source cycles

@LekoArts
Copy link
Contributor

LekoArts commented Mar 5, 2021

@juanbiberretta It's been released in gatsby-plugin-sass@4.0.1 :)

We publish a minor every two weeks and hotfixes ad-hoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
3 participants