Lots of good options here, just wanna throw my hat in the ring for plugin options that prevent pages from being created in the first place:
If it is a page component, i.e inside src/pages
folder, gatsby
use a plugin called gatsby-plugin-page-creator
to generate page, and it recently accept a ignore patterns.
There's a caveat, the built-in gatsby-plugin-page-creator
doesn't take user options, so we'd have to rename the pages folder to ignore it.
root
└── src
- └── pages
+ └── screens <-- rename
└── index.js
└── ignore-file-name.js
And then in gatsby-config.js:
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/screens`,
ignore: [`ignore-file-name.js`],
},
},
]
}
If it is a programmatically page generated from markdown or json, you might be able to ignore it in gatsby-source-file-system
, as pointed out in this github comment.
The example there even ignores file based on environment, which is more useful since you can still see your reference during development, but it won't show in build.
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content`,
ignore: process.env.NODE_ENV === `production` && [`**/draft-*`]
}
}
production
&& – Sheikdom