Home > database >  Gatsbyjs - Define Location of Static Pages as Something Other than the 'pages' folder
Gatsbyjs - Define Location of Static Pages as Something Other than the 'pages' folder

Time:05-24

As the title states, I'm unsure if it is possible to customize the folder Gatsby looks into to generate static pages. Apparently, this seems to be fixed without the ability to change from the pages/ folder. Ideally, this could be changed with something like an environment variable or similar. On the existing docs (https://www.gatsbyjs.com/docs/creating-and-modifying-pages/) nothing like this is mentioned.

Does anybody know if this is possible and I've just missed it somewhere? I've also opened this feature request discussion on the Gatsby GitHub: https://github.com/gatsbyjs/gatsby/discussions/35727

CodePudding user response:

You can use the gatsby-plugin-page-creator (official plugin from Gatsby staff) to customize the source of the /pages folder. Simply use it as:

{
  resolve: `gatsby-plugin-page-creator`,
  options: {
    path: `${__dirname}/src/account/pages`,
  },
}

Or using environment files:

{
  resolve: `gatsby-plugin-page-creator`,
  options: {
    path: `${__dirname}/src/${process.env.A_FOLDER_NAME}`,
  },
}

You can even use multiple instances of the plugin or ignore some files with the ignore option.

I've tested it recently and worked like a charm.

  • Related