Skip to content

Instantly share code, notes, and snippets.

@backlineint
Last active November 26, 2019 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backlineint/384863ac25841c3086b8bf32420e2c40 to your computer and use it in GitHub Desktop.
Save backlineint/384863ac25841c3086b8bf32420e2c40 to your computer and use it in GitHub Desktop.
Webpack Config for CSS Module and Sass Support in a Storybook for a Gatsby Project
// The require statement and the block within module.exports should be added to
// ./storybook/webpack.config.js
// Written for Gatsby v2 Storybook v5
const path = require("path");
module.exports = ({ config }) => {
// Update for SASS / CSS Modules support - minor adjustments to snippet
// from https://github.com/storybookjs/storybook/issues/6055#issuecomment-535450942
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
exclude: /\.module\.scss$/
})
config.module.rules.push({
test: /\.module\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
camelCase: 'dashesOnly', // Without this, styles with dashes will fail.
localIdentName: '[name]--[local]--[hash:base64:5]' // This will result in class naming that matches what is used when running Gatsby develop.
}
},
'sass-loader'
]
})
// For a gatsby project, you'll also likely need to make the webpack adjustments outlined here:
// https://www.gatsbyjs.org/docs/visual-testing-with-storybook/
return config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment