我已经在我的React项目故事书v5中安装了它。一切似乎都还可以,但是当我想将样式导入到我的react组件(我使用postcss-modules)时,出现错误Module not found: Error: Can't resolve './styles/Buttons'
。
我应该在故事书配置中添加什么以使其可行?我在项目中使用babel。
答案 0 :(得分:0)
您需要通过添加webpack
来定制Storybook的webpack.config.js
。
例如添加SASS
:
// @ webpack.config.js
const path = require('path');
// Export a function. Accept the base config as the only param.
module.exports = async ({ config, mode }) => {
// `mode` has a value of 'DEVELOPMENT' or 'PRODUCTION'
// You can change the configuration based on that.
// 'PRODUCTION' is used when building the static version of storybook.
// Make whatever fine-grained changes you need
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});
// Return the altered config
return config;
};
签出docs。