The more you use Gastby, the more you realize that this is more than just a static site generator: it is a full blown application server.
Bare bone Gatsby installation
For instance, you can install a bare bone version of Gatsby, without any starter, without any theme and not even any content:
Then you edit your package.json
file to add the scripts to start Gatsby:
and even though this directory is empty of any Gatsby specific file:
You can still start Gatsby:
As expected, the Gatsby rendered site, at the URL http://localhost:8000/
is kind of empty:
The GraphiQL explorer
The interesting part is with the GraphiQL explorer at http://localhost:8000/___graphql
You see that Gatsby has already a GraphQL server ready to return some data, like the time at which the site was started (buildTime
).
The GraphiQL explorer is the perfect tool to have a sneak peek in the internal data structure of Gatsby.
For instance, you can see the files being generated by Gatsby through the allSitePage
root:
and you can see that it only generated the 404 page and that this page was generated by a plugin called dev-404-page:
Gatsby plugins
Talking about plugins, you also have a quick access to the list of plugins:
and you see that there are already quite a few of them:
The plugins are the mechanism by which you can extend Gatsby to either add new static pages or add a single page application to the generated site.
You may notice that the gatsby-plugin-page-creator
appear multiple times, but it is instantiated with different options.
That’s again something you can explore with GraphQL:
that tells you where this plugin is looking to generate static pages:
The most important directory being the last one: this is where you can start writing your first page!
Gatsby-config file
You can add you configure the plugins you want to run with Gatsby in a gatsby-config.js
file.
This file allows you also to provide some meta information about your site like, for example:
If you restart your server, the GraphiQL explorer will show that there is now a new siteMetaData
property available in the Site
root.
As usual, you can retrieve the data using GraphQL:
Et voilà: