I’m converting my site’s front-end from a WordPress-generated site to a static front-end. Because I’ve got my WP sites on Trellis already, I’d like to leverage Trellis to serve the generated static site. Conceptually, what I think I need to do is update the deployment script to copy the static site into the correct location on the box, then update nginx config to serve from there except /wp/wp-admin/ & /wp-json/.
Could anyone provide any tips / suggestions for doing this? I’d like to avoid modifying the roles as much as possible, so if this is doable via variables, that would be ideal.
I kept seeing Gatsby being mentioned but I thought it was something like Hugo and certainly didn’t think it was possible to integrate it with WordPress. I started reading today and my mind is blown - an actual setup to turn WordPress sites into PWAs! I love optimizing for performance, what an exciting time!
@mAAdhaTTah thanks for sharing this. It would be awesome if you could share some other more important steps from your Sage/Bedrock setup. Or just links to the resources you used when creating your setup.
I’ve still got a couple of things to work out. I think the last remaining issue is I need to disable nginx’s microcaching, as I’m finding coming back to the site and the latest isn’t showing until I refresh and I think that’s cause. I also ended up splitting off the above hooks into a separate role, which I also need to update properly with variables and such. Then I broke that out into its own playbook so I could deploy the static site separately from the main WordPress site. Then, after all that, I configured my home desktop machine to deploy the static site automatically every hour.
I’ll write all this up into a blog post with everything once it’s settled down.
My initial nginx config overlooked the /app directory. Parts of the admin dashboard didn’t work because plugins were unable to load their assets. I’ve updated it as follows:
However, this does mean if you have any Gatsby paths that start with /app/, they won’t get served. I’m not sure this is a big deal, but it might be nice to have a fallback of some kind, attempting to serve from the Gatsby directory if it’s not found in the WP app directory. I don’t know how much of an issue that is (can’t imagine a lot of Gatsby sites have an /app path), but worth keeping in mind.