- 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.
When set to esnext, I was getting errors about trying to use ESM imports in a gatsby-* file (even though those were TS files). 🤷♂️