How do I add an arbitrary file to /public with Gatsby?

A bit late to the party.

The easiest way is to add static folder in your project root directory, then place _redirects inside it. Then when you build Gatsby will automatically pick that up and place it within /public folder.

See official docs


Didn't need to put it in /src. I just added it directly to /public.

Even though it's in .gitignore, I used git add -f /public/_redirects, committed it, and it worked. It doesn't get deleted or overwritten during build.


Another way to do this (which I haven't tested) is to is to copy the file to its destination in /public as part of a post-build script in gatsby-node.js.

Tags:

Gatsby

Netlify