19

I'm considering using LESS for CSS development with server (or development) side processing, but I can't decide if I should keep the generated CSS files in version control. There are plenty of solutions with hooks, but this adds software dependencies to the server. A hook could just be added locally so staging and production areas on the web would get the same files. So, the question is:

Should generated CSS files be included in version control or not? Please keep in mind that some frameworks require a CSS file to exist for a particular reason (i.e. WordPress themes require a style.css file in order to be recognized).

When I say 'considering using LESS', I mean it becomes a requirement. New developers would not have the option use vanilla CSS after the choice is in favor of LESS.

5 Answers 5

12

Checking in derived artifacts is almost always sub-optimal.

I vote no to checking in the .css. It's only a matter of time until one of your peers or successors checks in an edit to the .css and not the .less. Then when you change the .less the prior change is lost.

3
  • 1
    I would suggest leading the answer with the last line. Would make the answer flow a little better.
    – Roman
    Commented Nov 1, 2012 at 22:07
  • 1
    You mean not to check in .css?
    – Roman
    Commented Nov 1, 2012 at 22:45
  • This is one issue I am worried about. Developer edits CSS but not LESS, and then checks in the updated (previously generated) CSS file. A pre commit hook would even erase all changes made. Thanks for your input. Commented Nov 1, 2012 at 23:17
11

You've pretty much answered your own question. It depends on how you deploy your website.

If the server is just going to pull directly from the Git repository:

1) It needs to have software installed to generate CSS from LESS.

2) or you need to include the CSS files in the repository.

If you're not pulling straight from the repository on your web server, you could have a build script that pulls from git, generates CSS, and then transfers the content to the web server(s), possibly excluding unnecessary files from the transfer.

In my opinion, Git should be used to keep all of the source for a project, and none of the "derived artifacts" (as mentioned by @thekbb). Developers need to have all tools installed to generate those derived artifacts during development and test. For deployment to test and production servers, an automated build server should take the source and create just the files needed for distribution.

In the case of software development, you'd have a Makefile with .C and .H files (for example) in your Git repository. Developers and the build server have a compiler installed that will create an executable or compiled library. When the files are packaged for distribution, the source code is not a part of the archive.

For web development, you have source files like original graphics, HTML templates and LESS files. Developers and the build server can run scripts to generate the site assets (CSS from LESS files, static HTML pages from templates, flattened images in multiple sizes/formats, etc.) When the build server deploys new builds, it copies just the files needed by the server, excluding the source graphics, templates and LESS files.

If there are people that need to review the site content, they should do it on a staging server. If that's not possible, the automated build server can create a ZIP file on an internal server that they can download for review.

2
  • 1
    This is a great answer, but which choice do you think is optimal if you're using a framework that requires a CSS file like WordPress? Commented Nov 1, 2012 at 23:26
  • 1
    See my updated answer of what I think is optimal. Essentially what @thekbb says: don't store derived artifacts in your repository.
    – tomlogic
    Commented Nov 2, 2012 at 16:38
2

Should generated CSS files be included in version control or not?

In theory they should not, but for practicality, I do usually checks in the generated css file. The reason is that it simplifies deployment since I do deployment using git; I would not need to have a less compiler installed on the server and usually not even on the machine I'm deploying from (as opposed to the machine where I'm developing on). Doing this could be useful if you have separate developer and deployer, but can sometimes also be useful even if you're deploying yourself.

Now, there are drawbacks on doing this:

  1. You can't use git add --patch (or you really need to be very careful when doing so)
  2. You should not modify the .css directly; instead I usually use a secondary .css file to do minor modifications without modifying the primary .less or .css file. You can also compile .less file straight into a minified css, to make it less tempting to modify the generated css.
  3. Developers have to set up their machine to use automatic recompile tool (like SimpLess or Less.app), so the .css file is updated as soon as they save to the .less file. Without automation, you'll run into risk of the css not matching the checked-in less file.

I would not do the same when compiling from .C and .H files though, because the generated binary for those are platform specific, and also .less/.css file is usually a very small part of a larger web project so the space overhead of the additional file is small.

0

Good question. If you can absolutely guarantee that the CSS file gets updated when the LESS gets updated then perhaps yes - as per @Scott Simpson's comment. I suspect that this would be difficult to guarantee and what happens when the new developer get's a copy of CSS the day when they are out of sync? Also, of course, and I hadn't originally thought of this, what happens if the new developer then makes updates to the CSS file rather than the LESS?? If the CSS has to be built and isn't part of archive I can see less problems.

1
  • You bring up good points, but it would probably work better as an answer if rephrased the what would happen questions as a list of possible shortfalls.
    – Roman
    Commented Nov 1, 2012 at 22:01
-1

I would say yes -- because what happens if you want to add a developer to your workflow and they don't want or need to build .Less? It would be helpful for them to have access to only the generated file.

3
  • 4
    You could use the same argument for committing other build artifacts like executables or DLLs. In theory everyone would at least have the same tool chain installed and a build script to generate all the artifacts.
    – Roman
    Commented Nov 1, 2012 at 21:59
  • @Scott - LESS would be a requirement for the project if it's used. Commented Nov 1, 2012 at 23:23
  • @R0MANARMY Not the same argument in particular. It depends on if you care about your choice of version control handles binary data which many popular VCSs do not. I am referring to all textual data. Commented Nov 1, 2012 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.