CSS modules
See original GitHub issueHi, I’m trying to use SASS styles like this in my React components:
import React, { Component } from 'react';
import Drawer from 'material-ui/Drawer';
import { Link } from 'react-router' ;
import styles from './sidebar.scss' ;
class Sidebar extends Component {
constructor(props) {
super(props);
this.state = { open: true };
}
render() {
return (
<div>
<Drawer className={styles.drawer} open={this.state.open}>
<div className={styles.header}>
<Link className={styles.profilePic} to="#">Item</Link>
</div>
<Link className={styles.item} to="#">Profile</Link>
<Link className={styles.item} to="#">Dashboard</Link>
<Link className={styles.item} to="#">Charts</Link>
<Link className={styles.item} to="#">Calendar</Link>
</Drawer>
</div>
);
}
}
export default Sidebar;
Styles are working in my app normally, all good. But when I open them in storybook, styles won’t show up. Is this problem with my webpack setup for storybook? Here is how it looks like:
const path = require('path');
const autoprefixer = require('autoprefixer');
module.exports = {
module: {
loaders: [
{
loader: 'url-loader?limit=10000',
test: /\.(gif|jpg|png|svg)$/,
include: path.resolve(__dirname, '../')
}, {
loader: 'url-loader?limit=1',
test: /favicon\.ico$/,
include: path.resolve(__dirname, '../')
}, {
loader: 'url-loader?limit=100000',
test: /\.(ttf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
include: path.resolve(__dirname, '../')
},
{
loader: 'style-loader!css-loader',
test: /\.css$/,
include: path.resolve(__dirname, '../'),
exclude: path.resolve(__dirname, '../node_modules')
},
{
loader: 'style-loader!css-loader!sass-loader',
test: /\.scss$/,
include: path.resolve(__dirname, '../'),
exclude: path.resolve(__dirname, '../node_modules')
},
]
},
sassLoader: {
includePaths: path.resolve(__dirname, '../src/browser')
},
};
If I import styles with import './sidebar.scss' ;
and then write class names explicitly into classNames, then styles are used correctly in storybook (so SASS files are loaded without problem, loaders in webpack works).
What should I do if I want to use styles like I shown in my Sidebar component on top of this comment?
Issue Analytics
- State:
- Created 7 years ago
- Comments:20 (2 by maintainers)
Top Results From Across the Web
Documentation about css-modules - GitHub
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. All URLs (...
Read more >What are CSS Modules and why do we need them?
According to the repo, CSS modules are: CSS files in which all class names and animation names are scoped locally by default. So...
Read more >Component-Scoped Styles with CSS Modules - Gatsby
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. CSS Modules let...
Read more >Adding a CSS Modules Stylesheet - Create React App
CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. Learn more about CSS Modules...
Read more >A deep dive into CSS Module - LogRocket Blog
According to the official CSS Module GitHub repository, a CSS Module is a CSS file in which all class names and animation names...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For webpack 2 I’m using this in
.storybook/webpack.config.js
and it’s working fine:I got it to work, thanks. Just for future reference, if you want to just add css modules to your react storybook project:
add a webpack.config.js on your .storybook directory
put this inside: