Skip to content

Commit

Permalink
fix(gatsby-plugin-sass): add missing options (#27786)
Browse files Browse the repository at this point in the history
* fix(gatsby-plugin-sass): add missing options

`cssLoaderOptions` is not defined in the schema, so it will return an error when passing in these options.
See readme: 
```
If you need to override the default options passed into css-loader: Note: Gatsby is using css-loader@1.0.1.

plugins: [
  {
    resolve: `gatsby-plugin-sass`,
    options: {
      cssLoaderOptions: {
        camelCase: false,
      },
    },
  },
]
```

* Fix linting

* test(gatsby-plugin-sass): add testing for css loader option

Co-authored-by: Max Stoiber <contact@mxstbr.com>
  • Loading branch information
mikaelkristiansson and mxstbr committed Nov 3, 2020
1 parent 6615dbb commit 7c86973
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-sass/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe(`pluginOptionsSchema`, () => {
it(`should provide meaningful errors when fields are invalid`, async () => {
const expectedErrors = [
`"implementation" must be of type object`,
`"cssLoaderOptions" must be of type object`,
`"postCssPlugins" must be an array`,
`"sassRuleTest" must be of type object`,
`"sassRuleModulesTest" must be of type object`,
Expand Down Expand Up @@ -88,6 +89,7 @@ describe(`pluginOptionsSchema`, () => {
const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, {
implementation: `This should be a require() thing`,
postCssPlugins: `This should be an array of postCss plugins`,
cssLoaderOptions: `This should be an object of css-loader options`,
sassRuleTest: `This should be a regexp`,
sassRuleModulesTest: `This should be a regexp`,
useResolveUrlLoader: `This should be a boolean`,
Expand Down Expand Up @@ -117,6 +119,7 @@ describe(`pluginOptionsSchema`, () => {
it(`should validate the schema`, async () => {
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, {
implementation: require(`../gatsby-node.js`),
cssLoaderOptions: { camelCase: false },
postCssPlugins: [{ post: `CSS plugin` }],
sassRuleTest: /\.global\.s(a|c)ss$/,
sassRuleModulesTest: /\.mod\.s(a|c)ss$/,
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby-plugin-sass/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ exports.pluginOptionsSchema = function ({ Joi }) {
.description(
`By default the node implementation of Sass (node-sass) is used. To use the implementation written in Dart (dart-sass), you can install sass instead of node-sass and pass it into the options as the implementation`
),
cssLoaderOptions: Joi.object({})
.unknown(true)
.description(
`Pass in options for css-loader: https://github.com/webpack-contrib/css-loader/tree/version-1#options`
),
postCssPlugins: Joi.array()
.items(Joi.object({}).unknown(true))
.description(`An array of postCss plugins`),
Expand Down

0 comments on commit 7c86973

Please sign in to comment.