Hacker News new | ask | show | jobs
by ricksharp 2082 days ago
I use createPages and I get hot reloading when running gatsby develop.

I also just figured out how to trigger hot reloading for sources that normally don’t trigger it (markdown files which I was manually processing).

Basically, I discovered that gatsby will hot-reload when it sees a change in code files (.tsx). So I created an essentially empty _rebuild-trigger.tsx file and imported that in my main page template.

Now, to change the page content and trigger a hot-reload:

- I have an observable subscribed in createPagesStateful that calls deletePage and createPage - Then write to the file _rebuild-trigger.tsx file

I need to make a blog post because it works great (and I could tie it to any change source - like file system watcher - during development).

2 comments

Hmmm, I seem to recall that hot reload didn’t reload the content, but I’ll check again! In any case it’s not as smooth for allowing content editors to preview content as NextJS’s preview unless I’ve missed something - with Next it will reload the content on every page load if you have the preview cookie set
Please do share!
This commit has the important pieces. Look for the createPage call and rebuild-trigger.

I’ll try to put together a blog post when I can.

https://github.com/ricklove/rick-love-master/commit/8eebd4f9...

This looks very promising. I've given it a like, will take a deeper look when I get on the laptop. :)

Thanks a lot for sharing Rick!