【发布时间】:2018-12-16 10:54:50
【问题描述】:
我的目标是从本地插件创建页面。我编写了一个名为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`,
}
},
]
}
plugins/my-custom-plugin/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'
}
})
}
不幸的是,我在运行 gatsby develop 时收到错误消息The plugin "my-custom-plugin" created a page with a component that doesn't exist。我做错了吗?有什么帮助吗?
问候。
【问题讨论】:
标签: javascript reactjs gatsby