Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LESS and Version Control: Should generated CSS be included in a repo?

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.

like image 905
Brandon Bradley Avatar asked Nov 01 '12 20:11

Brandon Bradley


People also ask

How do I create a less CSS file?

Pre-compiling LESS into CSS: To compile LESS into CSS, we use the below command in a command prompt. The lessc command lets us precompile our LESS file into a basic CSS file. This helps us in writing modular code using LESS programming and still getting all the benefits of CSS by compiling it into traditional fast CSS.

How do I add less CSS in HTML?

Create a stylesheet with . less extension and link it in your document using the rel="stylesheet/less" attribute. You are all set and can compose styles within the . less .

What are less files?

Webpage style sheet used by LESS, a dynamic style sheet language that extends standard CSS with features such as variables, mixins, operations, and functions; requires the LESS JavaScript library (less.


2 Answers

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.

like image 146
thekbb Avatar answered Sep 16 '22 12:09

thekbb


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.

like image 23
tomlogic Avatar answered Sep 17 '22 12:09

tomlogic