Skip to main content

Local development with GatsbyJS and Drupal

Published on

As I have begun working with GatsbyJS once again, I am trying to find a way to work with GatsbyJS and Drupal locally in a somewhat streamlined fashion. Honestly, serving Drupal over PHP's built-in server and using the gatsby develop and gatsby serve command work just fine. But, I love tooling. And I want to test out using GatsbyJS custom environment setups to build variants of the GatsbyJS site. These variants would then map to Drupal Commerce stores, allowing a demonstration of the multisite and multilingual capabilities of Drupal Commerce.

I use DDEV on a daily basis, so that was my first stop. Kevin Bridges of DRUD Technology, who makes DDEV, gave a session at BADCamp. The Decoupled Drupal on DDEV with GatsbyJS session was less about serving both GatsbyJS and Drupal from DDEV through fancy Docker networks, and more about just using DDEV to serve Drupal locally. I really like DDEV's multiple domain support. I plan on trying to hack something together.

Next, I went to review J.D. Flynn's Docksal Decoupled setup. Docksal is a local Docker tool. I have not personally used it, but I am considering giving it a go-to test out J.D.'s setup. It is a monorepo setup that is based on ContentaCMS and GatsbyJS. The power is behind Docksal commands and some custom Apache vhost setup. I feel it is getting closer to what I am looking for!

Finally, I was pointed to Benji Fisher's Lando Gatsby Drupal setup. Lando runs all of the commands within its CLI containers. It resembles my goals a bit more. When you bring up the environment it will run the build on GatsbyJS and serve those files.

The problem that might bite me: trying to run multiple builds of off the same GatsbyJS app. I'll need to add additional environment types, which map to production or development as well, so that appropriate .env files are loaded.

I'm available for one-on-one consulting calls – click here to book a meeting with me 🗓️