Sorry, to open this again. I'm aware there were several issue before e.g. https://github.com/storybooks/storybook/issues/48 and https://github.com/storybooks/storybook/issues/755
But unfortunately none of these solutions seem to work in the latest version (3.2.8
). The storybook webpack doesn't complain but I don't get any of my styles because the class names that CSS Modules usually generates are now all undefined
.
Very happy about any ideas.
.storybook/webpack.config.js
copy-pasted from my normal webpack.config where it works
const path = require('path')
module.exports = {
plugins: [
// your custom plugins
],
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'css-loader',
options: {
camelCase: true,
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]--[hash:base64:5]'
}
},
'resolve-url-loader',
'postcss-loader?sourceMap'
],
include: path.resolve(__dirname, '../')
}
]
}
}
button.component.js
import React from 'react'
import styles from './button.styles.css'
export const Button = (props) => {
return (
<button className={`${styles.button} ${styles.big}`}
>{props.children}</button>
)
}
export default Button
button.styles.css
.normal {
padding: 5px 15px;
}
.big {
padding: 10px 50px;
}
.button {
background-color: var(--cta);
border: none;
border-radius: 8px;
color: var(--black);
cursor: pointer;
display: inline-block;
font-family: 'cinetype', sans-serif;
font-size: 18px;
line-height: 30px;
min-height: 40px;
min-width: 90px;
position: relative;
text-transform: uppercase;
}
postcss.config.js
const colors = {
black: '#141a2f',
cta: '#e3d841',
'dark-blue': '#172c81',
'light-blue': '#4884c2',
highlight: '#6bc3ff',
light: '#e8ecff',
'text-inactive': 'rgba(255, 255, 255, 0.4)',
white: '#fff'
}
// Why em instead of px? Glad you asked: https://cloudfour.com/thinks/the-ems-have-it-proportional-media-queries-ftw/
const mediaQueries = {
'--phone': '(min-width: 20em)', // 320px
'--tablet': '(min-width: 48em)', // 768px
'--desktop': '(min-width: 62em)', // 992px
'--large-desktop': '(min-width: 75em)' // 1200px
}
module.exports = {
plugins: {
'postcss-import': {},
'postcss-custom-properties': { variables: colors },
'postcss-custom-media': { extensions: mediaQueries },
'postcss-calc': {},
'postcss-color-function': {},
'postcss-cssnext': {
browsers: ['last 2 versions', '> 5%'],
warnForDuplicates: false
},
cssnano: {}
}
}
god i hate webpack. my bad, forgot style-loader
of course…
Most helpful comment
god i hate webpack. my bad, forgot
style-loader
of course…