gatsby-plugin-page-creator
Gatsby plugin that automatically creates pages from React components in specified directories. Gatsby
includes this plugin automatically in all sites for creating pages from components in src/pages
.
You may include another instance of this plugin if you'd like to create additional "pages" directories.
With this plugin, any file that lives in the the specified pages folder (e.g. the default src/pages
) or subfolders will be expected to export a React Component to generate a Page. The following files are automatically excluded:
template-*
__tests__/*
*.test.jsx?
*.spec.jsx?
*.d.tsx?
*.json
*.yaml
_*
.*
To exclude custom patterns, see Ignoring Specific Files
Install
npm install --save gatsby-plugin-page-creator
How to use
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/account/pages`,
},
},
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/settings/pages`,
},
},
],
}
Ignoring Specific Files
Shorthand
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/indexes/pages`,
ignore: [`blog.(js|ts)?(x)`],
},
},
],
}
NOTE: The above code snippet will only stop the creation of the /blog
page, which is defined as a React component.
This plugin does not affect programmatically generated pages from the createPagesAPI.
Ignore Options
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/examples/pages`,
ignore: {
patterns: [`**/*.example.(js|ts)?(x)`],
options: { nocase: true },
},
},
},
],
}