如何更改 Gatsby 的默认 `src` 目录
How can I change the default `src` directory for Gatsby
我想将 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
这是开放的issue 2424. It appears that until this issue is completed not much can be done. you can follow along here
你可以这样做:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/gatsby/pages`,
},
},
]
}
有关详细信息,请参阅 docs
我想将 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
这是开放的issue 2424. It appears that until this issue is completed not much can be done. you can follow along here
你可以这样做:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/gatsby/pages`,
},
},
]
}
有关详细信息,请参阅 docs