So I've been having this discussion with some co-workers and I'd like some other people to weigh in on this. I'm curious to see what other developers are doing.
What I like to do is ignore my entire build/assets folder from the repo. This folder contains my compiled CSS, Javascript, and compressed images. I think only the source files should be checked in. I find it annoying that every time I make a change to a stylesheet or JS file, I have to check in the source file AND the new compiled version. This also introduces merge conflicts and other issues when you have multiple people working on the project. I like to keep the repo nice and light and then have the developer build the project locally to get set up. Or when you deploy, have the server build out the project.
This is somewhat an issue, because my co-workers use Git as the deploy process. So when you want to deploy, you check your code into git, push it to the remote repo, and then you SSH into the server and do a git fetch && git pull. This means that ALL of the website files have to live in the repo. So I now have to check in my assets folder.
How do you guys handle this? I'm using bedrock-ansible
for a Wordpress site, and there's an option to run some commands right before it deploys, so I configured it to run npm install && gulp build
and build out the project, but the issue is that it was way too slow. The way bedrock-ansible works is that it creates a new release directory for each deployment, and it just symlinks the latest one to the current
directory. So each time I deployed, it ran npm install
when in reality, I only need those dependencies in one shared directory. There might be a way to do that with npm install --prefix install/dir
but I haven't tested it out yet. I think that might introduce more issues.
For now, I had to check in all of my compiled assets to git, to get this working. But on my gulp watch
task, I don't have any minification happening, but when I want to deploy, I want to run gulp build
first which will minify and uglify everything - so technically I would always have to make a commit when I want to deploy the site. It's a mess. What do you think is a good way to handle this?
gulp build
could put all compiled files in a dist/
directory and gulp publish
could push this directory to the remote. You can use git-directory-deploy for this:
$ git-directory-deploy --directory dist --branch master
Or you can manually set up a separate branch for compiled assets and push it to the remote server when deploying your website (this SO answer might help).
This way you can maintain a clean history on your development branch and not worry about merge conflicts while still using Git as a deploy process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With