New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to Change 'gatsby build' directory? #18975
Comments
So when |
@PiccoloYu We currently don't support a configurable output directory and don't plan to doing so in the near future. Let's follow along the conversation in #1878 Closing this |
Yes, you can. const path = require("path")
const fs = require("fs")
exports.onPreInit = () => {
if (process.argv[2] === "build") {
fs.rmdirSync(path.join(__dirname, "dist"), { recursive: true })
fs.renameSync(
path.join(__dirname, "public"),
path.join(__dirname, "public_dev")
)
}
}
exports.onPostBuild = () => {
fs.renameSync(path.join(__dirname, "public"), path.join(__dirname, "dist"))
fs.renameSync(
path.join(__dirname, "public_dev"),
path.join(__dirname, "public")
)
} |
Your solution works for me @abraaoz. |
based on abraaoz y resolve like this const path = require("path") exports.onPostBuild = () => { } |
Allowing us to run Github pages from master branch, while keeping the source code in the same file. Related resources: gatsbyjs/gatsby#18975 https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/
If you need the files in a different directory after build, you can npm i rsync -D and modify the gatsby build && rsync -av --delete public/ path/to/new/folder This will make sure that path/to/new/folder does not contain files, that are not in public/ and copies files over in one command. Using the rsync npm package will ensure cross-compatibility. This will leave the |
Hey all, could you help me understand what would be the use-case for making the build path configurable? |
Sure. I'm building a partial static page with WordPress (using WPGraphQL, etc.). So I want the landing page to be static. It's mostly a one page website / app that uses WordPress as headless CMS, but it also has some pages from WordPress itself, i.e. WooCommerce and account management, so I don't want to go for gatsby in full. I wanted to config the build path, so I can build into the child theme's sub-folder to end up with a theme that contains all the relevant stuff I need. My theme also handles some htaccess entries to make sure that the static landing page (and its JS / CSS / JSON) will open when navigating to It's certainly an edgy use-case, I agree, but it's the most cost-efficient route to get good SEO (due to insanely good loading speeds) and have most control about landing page, at the moment. |
I think this WOULD help a lot... I run gatsby for my blog on "/blog" and I run rails app on my "/" root... So, this is a need if you have multiple applications running on the same domain... I can't use a subdomain because I want to rank on SEO... |
I believe the |
for sure, projects with more complex build/scaffolding/deployment/serving requirements, such as those in many enterprise projects, could find this useful. For example, an organization using monorepo design patterns and having a standard build process (e.g distribution bundles being built to some other common location in the repository before getting picked up, optimized, combined, or served by some other processes). Basically without this capability, orgs need to then customize the build/serve/deploy tool just to handle this path instead (which is not a big deal btw, but i am just providing use-cases). |
My use-case would be, to be able to keep my Gatsby develop process running (which is pretty time consuming to start due to complex sourcing etc) while being able to create build while developing. Otherwise I need to do this by using the same git branch in 2 directories (1 directory for using for my actual local development and 1 directory for building the development environment online). |
@biel-fyq How about translating the error, so people can help? |
I would like to see this feature as well. In my situation I use gatsby to generate the website in a Firebase hosting project, but the project that contains the website also contains the code for functions, security rules, storage configuration and a host of other directories. Having Gatsby enforce an out directory that is not configurable makes it necessary to move/delete the public directory to some where that I need it. It's a very common thing to do in anything except the most basic websites. You really should consider adding this feature. |
How to Change 'gatsby build' directory?
The text was updated successfully, but these errors were encountered: