javascript - Next.js 与 Styleguidist 和 Fela (React)
问题描述
有人设法用 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?
可能是因为它缺少正确的应用程序根?
提前致谢。
解决方案
所以 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']
}
}
}
]
}
}
};
推荐阅读
- javascript - 如何检查函数是否抛出包含 Jest 文本的错误?
- mongodb - MongoDb 显示非白名单 IP 地址的连接
- python - 如果 Twilio 调用使用 Django 结束,如何在 sounddevice python 库中停止录音?
- python - 如何将行值相加并合并到pandas dataframe python 3中?
- html - 我的 CSS 编码没有反映在我的页面上
- json - Flutter中需要将API数据设置为条形图
- javascript - 如何从 `componentDidMount `(使用 Redux)获取状态?
- xml - 如何使用 powershell 创建一种 XML 结构的多种变体?
- sql - EF Core with Angular - 在 SQL Profiler 中快速查询,在实践中慢
- python - Tkinter Canvas create_window 函数未显示所需的小部件