gpt4 book ai didi

javascript - Storybook webpack 不会加载 scss 文件

转载 作者:行者123 更新时间:2023-12-03 13:53:59 24 4
gpt4 key购买 nike

当我运行故事书时,我没有收到错误,但我的样式都没有加载。请帮忙。我使用的是 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}/>
)
)

这是我的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";

最佳答案

也许这应该有帮助

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

关于javascript - Storybook webpack 不会加载 scss 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48273019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com