找不到带有故事书模块的CSS模块

时间:2019-05-24 09:51:31

标签: reactjs configuration babel css-modules storybook

我已经在我的React项目故事书v5中安装了它。一切似乎都还可以,但是当我想将样式导入到我的react组件(我使用postcss-modules)时,出现错误Module not found: Error: Can't resolve './styles/Buttons'。 我应该在故事书配置中添加什么以使其可行?我在项目中使用babel。

1 个答案:

答案 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