react-boilerplate-typescript +故事书设置不起作用

时间:2020-04-02 19:10:14

标签: reactjs typescript webpack storybook react-boilerplate

您好,我正在使用typescript version中的react-boilerplate,并尝试使其与故事书一起使用。我尝试了this reading指导的一些配置(有点陈旧,旨在用于非打字稿版本,但仍然有一些不错的建议),使用了storybook typescript preset和一些关于像thisthis这样的typescript + storybook配置。到目前为止,我的配置中仍然存在一些错误。我的配置档案是:

main.js:

const path = require('path');
const baseDir = path.resolve(__dirname, '../app');

// load the dev config from react-boilerplate
const devConfig = require('../internals/webpack/webpack.dev.babel');

module.exports = {
  stories: ['../app/**/*.stories.tsx'],
  addons: ['@storybook/preset-typescript', '@storybook/addon-actions', '@storybook/addon-links'],
  webpackFinal: async config => {
    // do mutation to the config
    config.module.rules = config.module.rules.concat(devConfig.module.rules);
    config.resolve.modules = [baseDir, 'node_modules'];
    config.resolve.extensions = ['ts', 'tsx', 'js', 'jsx' ];
    return config;
  },
};

和config.js:

import React from 'react';
import { configure, addDecorator } from '@kadira/storybook';
import { IntlProvider } from 'react-intl';

// import translation messages
import { translationMessages } from '../app/i18n';

// add a decorator to wrap stories rendering into IntlProvider 
const DEFAULT_LOCALE = 'en';
addDecorator((story) => (
  <IntlProvider locale={DEFAULT_LOCALE} messages={translationMessages[DEFAULT_LOCALE]}>
    { story() }
  </IntlProvider>
));

const req = require.context('../src/', true, /.stories.tsx$/);

// stories loader
function loadStories() {
  req.keys().forEach((filename) => req(filename))
}

// initialize react-storybook
configure(loadStories, module);

当前错误是:

ERROR in ./.storybook/config.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../app/i18n in /home/blabla/Documentos/estudio/react/prueba-react-boilerplate-typescript+storybook/.storybook
 @ ./.storybook/config.js 15:12-34

ERROR in ./.storybook/config.js
Module not found: Error: Cannot resolve directory '../src' in /home/blabla/Documentos/estudio/react/prueba-react-boilerplate-typescript+storybook/.storybook
 @ ./.storybook/config.js 34:10-59

这里是a link to the repo I'm working on。任何想法都会受到欢迎。预先感谢!

0 个答案:

没有答案