Gatsby.js is a static PWA (Progressive Web App) generator.
gatsby is a pretty popular JS tool to build websites using React. The question whether its possible to use it with CLJS has come up a few times in the past and I got curious in how shadow-cljs could help with that.
The basic idea is that you create normal CLJS
defn per “page” and slap some metadata on it. The metadata will be used by a shadow-cljs build-hook to create the
src/pages files that gatsby will look for. The files basically just map to the the CLJS defn to the data that gatsby expects. All code is written in CLJS and no JS code is used. The
site directory was generated by
gatsby new and the
shadow-cljs build will output the relevant files to
I would not recommend that anyone actually builds a full site using this since it is a pretty bad fit IMHO.
gatsby has certain assumptions that don’t map well to CLJS. What doesn’t work at all is the use of their
StaticQuery component since they process the actual JS AST to extract the queries at compile time. Since it doesn’t understand the code generated by CLJS it just fails to extract the queries. Not sure if that can be “fixed”.
I don’t ever plan on using gatsby myself but maybe this is useful for someone.