我想将Gatsby包含在已经使用src
作为应用程序代码源目录的现有代码库中。
我想在项目中创建一个名为gatsby
的子目录,并在根目录package.json
中安装所有依赖项。这将允许我使用Markdown + React构建一个静态站点,以展示组件及其支持文档,替换我项目中的Storybook。
目录结构是:
<root>
|- gatsby
| |- components
| |- layouts
| \- pages
|- src [my application's source code]
|- node_modules
|- package.json
\- gatsby-config.js
有没有办法告诉gatsby
使用gatsby
目录而不是src
?我尝试使用gatsby-plugin-filesystem
配置路径,但这对我不起作用:
module.exports = {
siteMetadata: {
title: 'Example'
},
plugins: [
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'src',
path: `${__dirname}/gatsby`
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'pages',
path: `${__dirname}/gatsby/pages`
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'layouts',
path: `${__dirname}/gatsby/layouts`
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'components',
path: `${__dirname}/gatsby/components`
}
},
'gatsby-plugin-react-helmet',
'gatsby-plugin-preact',
'gatsby-transformer-remark'
]
};
运行gatsby develop
时出现此错误:
error There was an error compiling the html.js component for the development server.
See our docs page on debugging HTML builds for help <link>
Error: Module build failed: TypeError: fileSystem.statSync is not a function
- exists.js:7 module.exports [project]/[babel-loader]/lib/utils/exists.js:7:25
- resolve-rc.js:13 find [project]/[babel-loader]/lib/resolve-rc.js:13:9
- index.js:113 Object.module.exports [project]/[babel-loader]/lib/index.js:113:132
答案 0 :(得分:0)
这是公开的issue 2424。似乎在这个问题完成之前不能做太多。你可以跟着here
答案 1 :(得分:0)
你可以这样做:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/gatsby/pages`,
},
},
]
}
查看docs了解更多详情