Gatsby: Change src directory to another directory name

Created on 12 Oct 2017  Â·  17Comments  Â·  Source: gatsbyjs/gatsby

Hi, I love gatsby!

But I'd love to change the name of the src directory to another name.
I can't figure out exactly how to tell gatsby about this change.

Thanks

Most helpful comment

My use case I was after when I landed on this issue is around having a gatsby site inside another repo and the gatsby code would be the docs for that site. So something like this:

<project-root>
  - docs (this is where gatsby would live)
  - src (this is where the project code would live)

And then have the publishing setup to use that docs directory instead of src.

All 17 comments

We don't support this atm. What's your use case for wanting to change the name?

@KyleAMathews It's not a really strong one, it's fine.

I just like using "app". Mostly because it appears at the top of my tree view. Kind of a petty use case...

Thanks any way

My use case I was after when I landed on this issue is around having a gatsby site inside another repo and the gatsby code would be the docs for that site. So something like this:

<project-root>
  - docs (this is where gatsby would live)
  - src (this is where the project code would live)

And then have the publishing setup to use that docs directory instead of src.

REPOST of #2839 : I see that src/pages path plus src/layouts or src/templates are hard coded directories in my project stack. The name src is conflicting with another src folder I have in my project. Therefore I wish there was a way I could designate a custom path for the folder I want gatsby to use for autogenerated pages.

component-page-creator.js is the file I supposed is responsible for this default behavior but when I introduced my change, the app broke. Other files of interest are

load-plugins.js
src/bootstrap/index.js 

The way I thought about introducing the custom path was through the gatsby-config.js because its loaded on bootstrap however it broke the query-watcher.js when I save the file with a change.

What is the best way to introduce this custom path?

src/templates is just a convention — do you mean src/pages?

If we want to make it possible to auto-create pages elsewhere, we should extract https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby/src/internal-plugins/component-page-creator to its own package then add a way to disable page creation. Then you could use the extracted package standalone to create pages from another directory.

Want to take that on?

@KyleAMathews I'm happy to give this a try although I will need a good bit of guidance. 😄

@nodox awesome! Want to create another issue and I'll add some suggestions there?

I would also love this feature to change the directory name. I have the same use case as @arsdehnel, where I want it to be in like a docs type folder, and my code for the actual project (non-gatsby stuff) is in the src folder. Has this ever been added, or is it still a pending feature?

@bluetidepro there's a nearly-complete PR for this over at https://github.com/gatsbyjs/gatsby/pull/4490

I would love to be able to split my app into code used to build the site (page creation, node manipulation, configuration etc) and code related to rendering the site (components, styles, view helpers, queries etc). This would involve two subdirectories - src/build and src/render. To make this work I would need to to be able to move src/pages and src/layouts into the render directory, however they are hard coded at the moment so this isn't an option.

@m-allanson Sweeeet. Can't wait for that to get merged!

Work has been intense. Looking to get back on this sometime within the next 2 weekends. @m-allanson.

No worries @nodox! Give yourself some downtime and come back to this whenever you're ready :)

@m-allanson It looks like this issue was closed in #4490, but I'm having a ton of trouble tracking down how to use it. I didn't see anything in the Gatsby Config documentation, and the PR is a bit difficult to follow. Would it be possible to provide a simple example?

Thanks!

Hey @LandonSchropp it's not possible to rename the src directory but you can tell Gatsby to generate pages from a custom directory. e.g. ./my-pages instead of the default ./src/pages. Check out the page creator plugin for more details: https://www.gatsbyjs.org/packages/gatsby-plugin-page-creator/

@m-allanson Thanks for the reply!

In case of monorepo having configs to change source code folder would be great

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dustinhorton picture dustinhorton  Â·  3Comments

benstr picture benstr  Â·  3Comments

andykais picture andykais  Â·  3Comments

kalinchernev picture kalinchernev  Â·  3Comments

totsteps picture totsteps  Â·  3Comments