故事书webpack不会加载scss文件

时间:2018-01-16 01:47:59

标签: javascript reactjs webpack sass storybook

我在运行故事书时没有收到错误,但我的样式都没有加载。请帮忙。我正在使用webpack 2.2.1。

我看了所有的S.O.和无数的G.H.问题答案无济于事。这是我的.storybook目录中的webpack.config.js



const path = require('path');

module.exports = {
    module: {
        rules: [
          {
            test: /\.jsx?$/,
            exclude: /(node_modules|bower_components)/,
            loader: 'babel-loader'
          },
          {
            test: /\.scss$/,
            use: [
              'style-loader',
              'css-loader',
              'sass-loader'
            ],
            include: path.resolve(__dirname, '../client/styles')
          },
          {
            test: /\.(ttf|eot|woff|woff2|svg)$/,
            loader: 'file-loader'
          }
        ]
    }
}




这是我的故事目录中的index.html:



import React from 'react';

import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';
import MenuOption from '../client/app/landingPage/components/menuOption'

import { Button, Welcome } from '@storybook/react/demo';
import { withInfo } from '@storybook/addon-info';
import '../client/styles/index.scss';


storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);

storiesOf('Component', module)
  .add('simple info',
    withInfo({
      text: 'String or React Element with docs about my component',
    })(() =>
    <MenuOption
      icon={'icon-knife'}
      text={"Orders to Cut Today"}
      isDisabled={false}
      isFocused={true}/>
    )
  )
&#13;
&#13;
&#13;

这是我的index.scss:

&#13;
&#13;
@import "basic";
@import "icons";
@import "_colors";
@import "_orders";
@import "_header";
@import "_navigation";
@import "_footer";
@import "_key-specification";
@import "_table-summary";
@import "_landing-page";
@import "_order-to-pack";
@import "_error";
@import "_instruction";
@import "_packed-boxes-table";
@import "_source-meat";
@import "_portion-sizes-table";
@import "_byproduct";
@import "components/index";
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

可能这应该有帮助

const genDefaultConfig = require('@storybook/react/dist/server/config/defaults/webpack.config.js');

module.exports = (baseConfig, env) => {
  const config = genDefaultConfig(baseConfig, env);

  config.module.rules.push({
     test: /\.scss$/,
     use: [
       'style-loader',
       'css-loader',
       'sass-loader'
     ],
     include: path.resolve(__dirname, '../client/styles')
  });

  config.stats = 'verbose';

  config.resolve.extensions.push('.scss');

  return config;
};