Gatsby 2.3.4 (latest) here, using the "ignore" option recently added to page creator plugin. see also https://github.com/gatsbyjs/gatsby/pull/11304
It seems this plugin is "added" to the existing gatsby default one. I'd expect this config replace the default gatsby one as it's using the exact same path.
The usecase is that I'd like to keep a /pages folder, but ignore the components being in /components folders.
What I'd like:
I expect the following config to match nothing, but actually adding the following did not produce any effect at all:
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/pages`,
ignore: {
patterns: [`**/*`],
},
},
},
A workaround is to simply not use the /pages folder, I can simply rename it to /page or something else, so that gatsby default config gets ignored, but this renaming seems a bit annoying to me.
That's the downside of gatsby-plugin-page-creator it's used to give users the option to easily mark other directories as pages directories.
It's not made to use on the default directory, sadly we will not fix this or enable this feature. Renaming your directory is the best solution at this time. You could always go for src/app/pages if you really want to keep the directory name 😛
Hiya!
This issue has gone quiet. Spooky quiet. 👻
We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 💪💜
Hey again!
It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks again for being part of the Gatsby community!
I don't understand why you couldn't add an option to override Gatsby's default page builder. I guess I'll also have to create another directory.
Came here from #11168, it seems to still be an issue.
My use case is:
src/pages directoryexamples folders that I want to ignore (they do not export React components)I get this error in the build script:
success createPages - 0.007 s
ERROR #11328
A page component must export a React component for it to be valid. Please make sure this file exports a React component:
/.../src/pages/.../examples/.../index.js
â ™ createPagesStatefully
There's no way to do this at the moment, as I can tell.
I tried using onCreatePage to deletePage again (like gatsby-plugin-exclude), but it only works in development mode for me (fails in production):
exports.onCreatePage = ({ page, actions: { deletePage } }) => {
if (page.path.match(/\/([^/]+\/){4}examples\/.*$/)) {
deletePage(page);
}
};
cc @sidharthachatterjee
I also believe this is what @bojan0624 meant in #16379. (cc @freiksenet)
Seems like this would be the spot to override options, if this would fit the goals of the Gatsby team:
Would something here like config.internalPluginOptions be an option?
// gatsby-config.js
module.exports = {
internalPluginOptions: {
'gatsby-plugin-page-creator': {
ignore: [`**/*.example.(js|ts)?(x)`]
},
// Other plugin options overrides, such as
// for `default-site-plugin` or something
},
// ...
}
This assumes, of course, that there will not be multiple instances of one plugin by a single name.
The implementation in /packages/gatsby/src/bootstrap/load-plugins/load.js could look something like this:
plugins.push(
processPlugin({
resolve: require.resolve(`gatsby-plugin-page-creator`),
options: {
path: slash(path.join(program.directory, `src/pages`)),
pathCheck: false,
+ ...(config &&
+ config.internalPluginOptions &&
+ config.internalPluginOptions[`gatsby-plugin-page-creator`]
+ ),
},
})
)
I guess for now, a workaround is to use patch-package to apply the fix manually:
node_modules/gatsby/dist/bootstrap/load-plugins/load.js file with your ignore. For example, my edit: plugins.push(
processPlugin({
resolve: require.resolve(`gatsby-plugin-page-creator`),
options: {
path: slash(path.join(program.directory, `src/pages`)),
pathCheck: false,
+ ignore: [`**/examples/**`]
},
})
)
Edit your package.json file to add the postinstall script:
"scripts": {
+ "postinstall": "patch-package"
}
Then install patch-package and generate a patch file (this will be applied to the fresh files every time on yarn or npm install).
Option 1: with yarn
yarn add patch-package postinstall-postinstall
yarn patch-package gatsby
Option 2: with npm
yarn add patch-package postinstall-postinstall
yarn patch-package gatsby
After this is done, you can commit the file in the patch directory so that they are applied every time.
@wardpeet Oh, just reading your note now that we will not fix this or enable this feature. 😩
Can the core team please reconsider this position? Maybe in light of the new information (none of Gatsby's current APIs like onCreatePage can be used to deletePage on pages that are invalid - even plugins cannot achieve this)?
Even if it wasn't such a heavy-handed approach like internalPluginOptions, just something to exclude from the list of pages in the default directory would be nice...
Sorry for reopening, I thought it was closed because of the bot.
An acceptable alternative would be to make onCreatePage with deletePage() calls (example and error above) work identically in production (gatsby build) as they do in dev (this code currently works in dev).
If you like to work around this issue without doing to much magic. You can use the following snippet in gatsby-node.js. Don't forget to npm install --save-dev gatsby-page-utils
const {
ignorePath,
} = require(`gatsby-page-utils`)
exports.onCreatePage = ({ page, actions }) => {
const { createPage, deletePage } = actions
if (!ignorePath(page.path, `**/examples/**`)) {
return;
}
deletePage(page);
}
We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 💜
@wardpeet as I mentioned above in https://github.com/gatsbyjs/gatsby/issues/12937#issuecomment-523030887, this onCreatePage workaround does not work in production if the JavaScript file is an invalid Gatsby page (such as with an empty example file).
If onCreatePage also worked in a production build, then I think this workaround would be totally fine.
Repro steps:
examples folder with an empty JavaScript fileonCreatePage workaroundgatsby buildI've created a new issue with all the information to allow overriding gatsby-plugin-page-creator.
We're happy to get PRs for it. I'll be closing this one in favour of https://github.com/gatsbyjs/gatsby/issues/17379
Thanks! Subscribed to #17379 now.