【问题标题】:Next.js with Styleguidist and Fela (React)Next.js 与 Styleguidist 和 Fela (React)
【发布时间】:2018-11-23 16:14:11
【问题描述】:

有人设法使用 Fela 和 Styleguidist 设置 next.js 吗?

Styleguidist 需要 Next.js webpack 配置,但是我不能像这里提到的那样链接它:https://react-styleguidist.js.org/docs/webpack.html

我正在使用这个示例应用程序:https://github.com/zeit/next.js/tree/canary/examples/with-fela

这是我的 styleguide.config.js 的样子:

module.exports = {
components: 'components/**/*.js',
webpackConfig: {
    entry: './pages/_document.js',
  module: {
    rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: "babel-loader",
            options: {
                presets: ['@babel/react']
              }
          }

        }
      ]
  }
}

};

该应用程序在 Next.js 服务器上完美运行,但是 Styleguidist 服务器收到以下错误消息:

错误:createComponent() 无法在上下文中没有渲染器的情况下渲染样式。应用根目录下缺少 react-fela?

可能是因为它缺少正确的应用程序根目录?

提前致谢。

【问题讨论】:

  • 您是否尝试过文档中的解决方案? react-styleguidist.js.org/docs/thirdparties.html#fela
  • 感谢回复,是的,我有,问题是styleguidest需要Next.js webpack配置。您所指的示例未使用 Next。
  • 您看到的错误表明您需要使用 Fela 提供程序,文档中的示例显示了如何执行此操作。什么不适合你?
  • 您的评论实际上为我指出了一个解决方案,我忘记在我的 styleguide.config.js 中添加 styleguidist 的包装器......所以干杯@ArtemSapegin!

标签: javascript reactjs next.js react-styleguidist


【解决方案1】:

所以 Artem 向我指出了一个解决方案,以防有人像我一样被卡住,你应该像这样添加一个包装器: styleguideComponents: { Wrapper: path.join(__dirname, '/FelaProvider') },

所以我的 styleguide.config.js 如下所示:

    const path = require('path')

    module.exports = {
        components: 'components/**/*.js',
        styleguideComponents: {
        Wrapper: path.join(__dirname, '/FelaProvider')
        },
        webpackConfig: {
            entry: 'next/lib/app.js',
        module: {
            rules: [
                {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ['@babel/react' ],
                        plugins: ['@babel/plugin-proposal-class-properties']
                    }
                }

                }
            ]
        }
        }
    };

【讨论】:

    猜你喜欢
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 2019-06-14
    • 2021-04-01
    • 2021-10-10
    • 2021-07-23
    • 2019-12-27
    相关资源
    最近更新 更多