Roots Discourse

Gitignore ignore /dist directory? Why?

Ok, so i am a very new to wordpress development.

I have setup a server on amazon aws which i have wordpress already installed and running on that is my production server. I have setup a development environment on my local machine running on mamp and have a github repository where i push all my dev changes to. I then push those changes onto my production server when they are ready.

So my question and where i get confused is, when i push my changes to the production server the /dist folder is ignored through the .gitignore file for whatever reason, and my site doesn’t build cause it is trying to pull resources from a folder (dist) that technically does not exist. I have been researching and most developers say you should not run gulp on your production server. So what am i missing or not doing that i should be, so that when i push to my live server i have a completed build of my website? Same as if i were to run the gulp command on my development (local) environment and everything builds beautifully.

Are you using Trellis? If so, this is intended behavior, so that we’re not committing compiled assets to Github. With Trellis, the design is to use Deploy Hooks to compile and transfer /dist to the server during deployment.

Briefly, take look at trellis/deploy-hooks/build-before.yml. If you’re using Sage9 you can uncomment as the file instructs and it’ll work automatically. For Sage8 you’ll want to use this version, which we should really do a better job of calling out for Sage8 users.

If you’re NOT using Trellis, it might make sense to simply remove /dist from your .gitignore and commit it to your repository so that you can include it in whatever your deployment plan is.

Does that help?


Thanks for the reply MWDelaney,

I am not using trellis cause i like mamp. I have done exactly what you said, with removing the /dist from the .gitignore, but my concern is this is not entirely proper with industry standards. I guess what i want to know is what are the steps to deploy the sage theme correctly in the event your not using trellis.

Build artifacts aren’t usually committed, only the source (asset) files and tasks/scripts/Makefiles that build them (to dist/). There is the possibility of “dirty” commits which would also include build artifacts. Go-lang projects often do this with library dependencies. Both of course is possible and opinions differ.


Hey @follano, Austin Pray has a great post on this at which compares a few different ways of approaching this.

I think the simplest way, as @MWDelaney has said, is to let Trellis manage the deployment for you, where it will build the assets on your own machine and push them up to the server. If you still wanted to stick with MAMP you could write a bash script to build the files and copy them onto the server for you, or you could commit the /dist folder to Git but from experience that method gets messy quite quickly.

Thanks for all the insight guys, I am learning a lot! So I went ahead and set up bedrock-capistrano for my deployments. Everything is working beautifully, but i’m having another error now when I include capistrano/npm (so eventually i can run gulp to build everything before deployment). For some reason i am getting this error when i run bundle exec cap production deploy.

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::runner::ExecuteError: Exception while executing as serveruser@serverip: npm exit status: 127
npm stdout: Nothing written
npm stderr: /usr/bin/env: npm: No such file or directory

SSHKit::Command::Failed: npm exit status: 127
npm stdout: Nothing written
npm stderr: /usr/bin/env: npm: No such file or directory

Tasks: TOP => deploy:updated => npm:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as serveruser@serverip: npm exit status: 127
npm stdout: Nothing written
npm stderr: /usr/bin/env: npm: No such file or directory

Im stumped, but i know this is something really dumb. BTW, I am using a bitnami lamp stack…

npm cannot be found, are you running npm on the target/production server?
Build should be rather performed on your workstation/deploying machine.
Have you node already installed? Are you using a node version manager like nvm?

No node is not installed of the production server that im aware of. I thought capistrano would do this for me during the deploy?