- When Gatsby starts up, it will read
gatsby-config.js
first. - As you can see below, we use that file to
require('ts-node').register()
which registers a TypeScript evaluator that will be used when Gatsby reads all other API Javascript files. In other words, we only need to do this once in our entire codebase and not in other Gatsby files likegatsby-node.js
. - Our
gatsby-config.js
re-exports all the exported variables available ingatsby-config.ts
. - Later, since the
ts-node
evaluator is still active, Gatsby will loadgatsby-node.ts
instead ofgatsby-node.js
. - The same thing is true of other gatsby files; e.g.
gatsby-browser.ts
can be used instead ofgatsby-browser.js
.
I didn't come up with all of this on my own. I mentioned all the sources in the original gist.
@mokyox you need to create the
slug
fields first. You can do this on theonCreateNode
hook:The
createFilePath()
action is provided bygatsby-source-filesystem
and offers a couple options to generate the slug in case you want to change the base path (i.e. put it under a subfolder) or remove the trailing slash.