-
Notifications
You must be signed in to change notification settings - Fork 19
[Bug] Doesn't work with CSS modules #29
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I'm currently using both global CSSes and CSS modules, and can't replace my custom webpack config with this addon.
Another part of the issue is that current implementation of addon-postcss is adding another rule for CSS rather than replacing the default Storybook's one, if I'm correct?
Steps to reproduce the behavior
The following config won't load CSS modules.
{
name: '@storybook/addon-postcss',
options: {
styleLoaderOptions: {},
cssLoaderOptions: {
modules: true,
sourceMap: true,
},
postcssLoaderOptions: {
implementation: require('postcss'),
postcssOptions,
},
},
},
However, specifying two separate rules for webpack would work:
function applyCssConfig(config) {
const cssRuleIdx = config.module.rules.findIndex(({ test }) => test.toString() === '/\\.css$/');
const cssRule = {
test: /\.css$/,
include: path.resolve(__dirname, '../'),
exclude: /\.module\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { importLoaders: 1, sourceMap: true } },
{ loader: 'postcss-loader', options: { postcssOptions }, },
],
};
const cssModulesRule = {
test: /\.module.css$/,
include: path.resolve(__dirname, '../'),
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { importLoaders: 1, modules: true, sourceMap: true } },
{ loader: 'postcss-loader', options: { postcssOptions } },
],
};
config.module.rules.splice(cssRuleIdx, 1, cssModulesRule, cssRule);
return config;
}
Expected behaviour
Ideally I'd like to see both rules configured when I pass modules: true to css config...
Additional context
It might be related with #23 although I'm not sure if supporting modules should be treated as specifying another file extension...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working