简体   繁体   English

Storybook webpack 不会加载 scss 文件

[英]Storybook webpack will not load scss files

I'm not getting an error when I run storybook but none of my styles are loading.我在运行 storybook 时没有收到错误,但我的样式都没有加载。 Please help.请帮忙。 I'm using webpack 2.2.1.我正在使用 webpack 2.2.1。

I've looked at all of the SO and countless GH issues answers to no avail.我已经查看了所有 SO 和无数 GH 问题的答案,但无济于事。 Here's my webpack.config.js within my .storybook directory这是我的 .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' } ] } }

Here is my index.html within my stories directory:这是我的故事目录中的 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}/> ) )

And here is my index.scss:这是我的 index.scss:

 @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";

Probably this should help可能这应该有帮助

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;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM