Skip to main content

Behind the Scenes with Gatsby Internals

Curious how Gatsby works under the hood? The pages in this section describe how a Gatsby build works from an internal code/architecture point of view. It should be useful for anyone who needs to work on the internals of Gatsby, or for those who are simply curious how it all works, or perhaps you’re a plugin author and need to understand how core works to track down a bug? Come one, come all!

If you’re looking for information on how to use Gatsby to write your own site, or create a plugin, check out the rest of the Gatsby docs. This section is quite low level.

These docs aren’t supposed to be definitive, or tell you everything there is to know. But as you’re exploring the Gatsby codebase, you might find yourself wondering what a concept means, or which part of the codebase implements a particular idea. These docs aim to answer those kinds of questions.

A few more things. These docs are mostly focused on the build lifecycle (gatsby build). Operations specific to the develop lifecycle (gatsby develop) are mostly ignored. Though this may change in the future. Also, they mostly focus on the happy path, rather than getting bogged down in details of error handling.

The graph below shows roughly how all the sub systems of Gatsby fit together and the input/output artifacts at different parts of the build. To find out how different parts work, click on the nodes in the graph, or use the menu on the left.

graphnamecluster_legendLegendgatsbyGatsbyreduxredux namespacecachesite/.cache/publicsite/public/siteDatasite/external datadataSourcedata sources. e.g file, contentfulsourceNodessource nodesdataSource->sourceNodesnodesnodessourceNodes->nodesnodesTouchedtouchedNodessourceNodes->nodesTouchedrootNodeMaprootNodeMapsourceNodes->rootNodeMapgenerateSchemagenerate schemanodes->generateSchemaschemaschema (inc resolvers)nodes->schemarootNodeMap->generateSchemapluginResolversplugin resolverspluginResolvers->generateSchemagenerateSchema->schemacreatePagessite.createPagesschema->createPagesrunQueriesextract and run queriesschema->runQueriescomponentFilesReact components (src/template.js)componentFiles->createPagespagespagescreatePages->pagescomponentscomponentscreatePages->componentspages->runQuerieswritePageswritePagespages->writePagesbuildHtmlbuild-html.jspages->buildHtmlcomponents->runQueriescomponents->writePagesfragmentsquery fragments *.jsfragments->runQueriescomponentsWithQueriescomponents (with queries)runQueries->componentsWithQueriesqueryResultsJSON result /public/static/d/dataPathrunQueries->queryResultsdataPathsjsonDataPathsrunQueries->dataPathscomponentChunkscomponent chunks component---src-blog-[hash].jsqueryResults->componentChunksdataPaths->writePagesdataJsondata.jsonwritePages->dataJsonasyncRequiresasync-requires.jswritePages->asyncRequiressyncRequiressync-requires.jswritePages->syncRequirespagesJsonpages.jsonwritePages->pagesJsonproductionAppproduction-app.jsdataJson->productionAppstaticEntrystatic-entry.jsdataJson->staticEntryasyncRequires->productionAppsyncRequires->staticEntryappWebpackconfigure webpack (`build-javascript`)buildJavascriptbuild-javascript.jsappWebpack->buildJavascriptproductionApp->buildJavascriptbuildJavascript->componentChunksappChunkapp-[hash].jsbuildJavascript->appChunkwebpackStatswebpack.stats.jsonbuildJavascript->webpackStatschunkMapchunk-map.jsonbuildJavascript->chunkMapwebpackStats->staticEntrychunkMap->staticEntryhtmlWebpackconfigure webpack (`build-html`)htmlWebpack->buildHtmlstaticEntry->buildHtmlpageRendererpage-renderer.jsbuildHtml->pageRendererhtmlFileshtml files (index.html)buildHtml->htmlFilespageRenderer->buildHtml
Edit this page on GitHub
Docs
Tutorials
Plugins
Blog
Showcase