使用react-scripts @ next和css模块的故事书

时间:2018-06-14 18:46:36

标签: create-react-app css-modules storybook react-scripts

我尝试使用react-scripts @ next 2.0.0-next.66cc7a90(create-react-app v2),因为已经添加了对css模块的支持。不幸的是,故事书忽略了css模块。我能做什么快速修复?

1 个答案:

答案 0 :(得分:0)

我的解决方案是在webpack.config.js文件夹中创建一个.storybook,以启用CSS模块。

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        exclude: /\.module\.css$/,
        use: [
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
            options: {
              modules: false,
            },
          },
        ],
      },
      {
        test: /\.module\.css$/,
        use: [
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
            options: {
              modules: true,
            },
          },
        ],
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {},
          },
        ],
      },
    ],
  },
};