Why is the dist folder gitignored if it's required for the site to function? Okay to stop ignoring?

Just starting out with Sage and have perhaps a dumb question.

Why is the dist folder, with the stylesheet and other assets required for the theme to function, gitignored?

Every other site I’ve developed with always committed assets that were required for the site to work, but in Sage this doesn’t seem to be the case.

Which brings me to my second question, do you see any harm in me removing this from the ignore for our theme? This way we can just do a “git pull” on production and the site will work without having to use some other method to get the assets live.

Sage is built for the Roots stack first. When deploying through Trellis, the assets are built as a step. This ensures that they are being built for production and not accidentally for another environment. Also, hypothetically, if you were to commit changes to the dist folder with yarn start running, there could be a lot that would be wrong as yarn start isn’t really doing the same thing as yarn build (check out the dist folder to see what I mean — styles will be missing).

It’s not recommended, but you can remove dist from the .gitignore if this doesn’t work for your current setup, just make sure to run yarn build:production before committing changes. (edit:) This isn’t a fool-proof solution, especially when working on a team. Building production assets as a step in your deployment process would be the better, more “safe” way.

1 Like

The dist folder is .gitignore'd in Sage because assets created by the build should not be included in your Git repository

1 Like

Ah, we have to deal with a lot of crappy production servers where we can’t install npm/yarn. Or the server runs apache which I’m pretty sure Trellis sets things up to use nginx?

Trying to find a good way to build the assets and deploy them to production on servers that can’t use npm. We have git at least on almost every server.

I’m guessing if we can’t run yarn build:production on the server, and can’t use Trellis except for projects where we get to pick the server, the best method would be to just rsync after a git pull?

Sorry, and thanks for the help.

Ah sorry, I’m used to doing things in a Laravel-y kind of way, where the compiled assets get committed and pushed/pulled to production. New to this, and can’t run yarn on almost any of the servers we’re using.

You can do it this way with Sage. Before I switched to Trellis completely I committed my compiled assets to Git and deployed either via FTP or git clone. It’s a fine way to do it, it’s just not the way Sage is set up by default.

It’s considered a best practice to never include generated content/assets in a Git repository. Regardless of what platform you’re building on this should be followed whenever possible :slight_smile:

If you’re using Git as a deployment tool (which is better than FTP, but still not ideal) and can’t execute build commands, then just include them and be done with it :wink:

Semi-related question then.

Spent a couple hours getting acquainted with Capistrano. (Trellis looks nice but we can’t adopt it for everything so I’d rather not confuse everybody by introducing two new tools)

Would you by any chance know how to tell Cap to run composer install in sage’s folder, and not just in the root bedrock folder?

execute :composer, "install --no-dev --quiet"

worked fine for Bedrock, but I need to somehow run the same thing in a separate directory and Google is not helping lol. I suppose I could ask Stack, unless you know by any chance?

Just to make sure if I got this right: There are two options:

  1. I enable the syncing of the /dist folder via Github by deleting “dist” from the .gitignore file

  2. I run yarn build:production on my production server in the site directory “/site-name/current”? --> because I tried that, and it says ERROR: [Errno 2] No such file or directory: 'build:production'

I couldn’t use Trellis because we have shared hosting, so I wrote a custom deploy script in bash, that builds everything locally (git clones to temp folder, then runs composer, yarn build, removes unneeded production stuff etc.) then scp’s zip to the server and then connects via ssh and unzips and does some other stuff like activating theme, plugins etc., checking for .env file … If you should need something like that do let me know, don’t mind sending it to you and you can adjust it for your needs, it’s fully commented.

Please share if you do not mind.

Here you go, I adjusted variables and added some more comments for you, but it might still be too specific for your use. It can perhaps still be used as a starting point if you adjust it to your needs: https://pastebin.com/y6hkUqg8

1 Like