I've scenario with 5 different templates and more than 50 pages on my site.
I'd like to know if there is a cli option for gatsby which allow me to render only one given page. So If I only change the content for one page ( one url on my app ) then only that static file is generated and it doesn't update everything on my app.
Something like:
gatsby generate /mysite/mypage.html
And that specific page is updated and generated quickly, so the gatsby process does not have to process everything on my site.
Is that something I can achieve ?
Thanks!
I guess you can implement this behavior using gatsby-node.js API and a environment variable, with something like:
exports.onCreatePage = ({ page, boundActionCreators }) => {
const { createPage, deletePage } = boundActionCreators; // renamed to `actions` in Gatsby v2
const singlePageMode = process.env.SINGLE_PAGE !== undefined;
if (singlePageMode && !/404/.test(page.path) && page.path !== process.env.SINGLE_PAGE) {
deletePage(page);
}
};
and then, when you only want to build a single page: SINGLE_PAGE="/mypage" gatsby build
Hi @mquandalle ,
Thanks for that, but I guess with that approach we still need to generate all the project and later on remove the pages we don't need. Did I understand well?
The main reason I asked for a single page approach is to save time and being able to render a preview when I change something on my CMS.
The onCreatePage function is called at the beginning of the bundling process, when pages aren't built yet, so you'll indeed save time by using something like the above.
This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.
I have a SSR issue, I would like to debug the problem without having to rebuild the whole app between each iteration. It's frustrating.
Similar need here, my use case is previewing individual WordPress pages when using:
https://www.gatsbyjs.org/docs/sourcing-from-wordpress/
The content is managed in WP, the page generation in Gatsby, but would like to visualize individual WP pages as I create/update them without having to rebuild everything.
What about allowing to pass a series of node ids to the localhost:8000/__refresh endpoint as body or URL parameters and make those available in gatsby-node.js/createPages to decide to refresh 1 or multiple specific pages? (similar to https://github.com/gatsbyjs/gatsby/issues/5496#issuecomment-394076283 except we replace env variables with URL parameters)
What about allowing to pass a series of node ids to the
localhost:8000/__refreshendpoint as body or URL parameters and make those available ingatsby-node.js/createPagesto decide to refresh 1 or multiple specific pages? (similar to #5496 (comment) except we replace env variables with URL parameters)
I like that approach, it would make it easier to create hooks in CMS to automatically re-generate content on change when using 3rd party services.
@spik3s : Yes, keeping a REST-based approach instead of environment variables would make Gatsby a lot more interoperable. With Wordpress the integration becomes trivial:
To be placed in functions.php:
function gatsby_refresh( $post_id, $post, $update ) {
// send $post_id to http://localhost:8000/__refresh
return true;
}
add_action( 'save_post', 'gatsby_refresh', 10,3 );
Closed by the bot due to inactivity in 2018. Reopening due to activity since then, and no official solution for this very common use case.
This has been superseded by https://github.com/gatsbyjs/gatsby/issues/5002 and is solved with Incremental Builds. Locally this always worked withing gatsby develop and refresh env var.
Thanks for pointing to #5002, @LekoArts. If I understand correctly,
gatsby-develop worksI believe @jquintozamora was asking in the OP was asking about generating just one page in production.
@LekoArts, can you please clarify how to re-render just one page in production without Gatsby Cloud?
@LekoArts, can you please clarify how to re-render just one page in production without Gatsby Cloud?
I am also interested in this 馃憖
Any updates?
Most helpful comment
I have a SSR issue, I would like to debug the problem without having to rebuild the whole app between each iteration. It's frustrating.