javascript - 在 GatsbyJS 中从本地插件创建自定义页面时出错
问题描述
我的目标是从本地插件创建页面。我写了一个名为my-custom-plugin
. 我还安装了gatsby-plugin-page-creator
插件来自动从默认pages
目录之外的组件创建页面。
这是我的项目结构:
plugins
/my-custom-plugin
/gatsby-node.js
/package.json
src
/components
/pages
/single.js
gatsby-config.js
gatsby-node.js
...etc
gatsby-config.js(从根目录):
module.exports = {
plugins: [
`my-custom-plugin`,
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/components/pages`,
}
},
]
}
插件/我的自定义插件/gatsby-node.js
const path = require('path')
const location = path.resolve(__dirname, '..', '..', '/src/components/pages')
exports.createPages = ({ actions }) => {
const { createPage } = actions
createPage({
path: `/sample-page`,
component: `${location}/single.js`,
context: {
slug: 'sample-page'
}
})
}
不幸的是,我The plugin "my-custom-plugin" created a page with a component that doesn't exist
在运行 gatsby develop 时收到错误消息。我做错了吗?有什么帮助吗?
问候。
解决方案
https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-page-creator
您不需要自定义插件。自述文件指出您只需将配置插入gatsby-config.js
.
您当前的本地插件尝试完全按照页面创建器插件所做的工作。
推荐阅读
- docker - 将Springboot webapp部署到Docker时Keycloak适配器无法验证令牌
- sql-server - ASP .Net Core 2.2 中的 AlwaysEncrypted 得到错误字节 []
- excel - 为大量迭代提高 Excel VBA 循环的速度
- gnuplot - Is there a gnuplot setting to interpret ints as floats?
- css - 如何使用 gulp-clean-css 编写新的 -min.css 文件,而不是默认覆盖现有的 css 源文件?
- php - nginx try_files php file is not parsed
- java - How should I implement a horizontal win algorithm for my Connect 4 program?
- windows - 无法创建终点。指定端口出错
- python - Stanfordnlp python - 句子拆分和其他简单功能
- php - 如何修复“必须声明标量变量“@int”