3

I recently started working with LESS, and as I did some research to automated builders like Jenkins and Grunt, it seemed a common piece of advice was not to store LESS files on the repo, or not to have them on the live server, just the compiled CSS.

So I was hoping to get some advice on this. It seems that as LESS files are part of the project, storing them is necessary. But it makes sense not to have extra, random files on the live server. Deleting them myself seems the wrong way to do it every build, plus time consuming. I assume I can get automated builders to do it for me, though I don't yet know how. The most straight forward way would seem to be to not pull them down in the first place.

Or am I thinking about repos the wrong way? Should I have a different file storage medium for storing the LESS files, and others? I already don't store my PDFs on the repo, should I treat LESS the same? How should I store these files?

Rohit
  • 3,018
  • 2
  • 29
  • 58

1 Answers1

1

The conflict comes from aggregating source management and release management: you are using the same referential to:

  • store sources (from which you can build releases, included the compiled CSS files),
  • and to deploy (part of the release process)

The article "The Ideal LESS Workflow with git" suggests a pre-commit hook to make sure the css are always in sync with LESS changes, but that means storing generated content in the git repo itself.

I would rather:

  • push to a bare repo
  • have a post-receive hook which would:
    • checkout that bare repo in the target folder (the live site)
    • build the compiled css (compressed with lessc)
    • remove all less files
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the thought. Are you suggesting doing that manually? – Rohit Aug 26 '14 at 11:38
  • @RhoVisions no, I am suggesting to write a post-receive hook script (in the language of your choice) which will checkout, build and remove, in order to get the expected target live folder. – VonC Aug 26 '14 at 11:39
  • Ah, ok, never done that before, so I guess its off to researching. – Rohit Aug 26 '14 at 14:34
  • @RhoVisions the checkout part of the post-receive hook is explained in http://stackoverflow.com/q/10507942/6309, also illustrated in http://stackoverflow.com/a/23048260/6309 or http://stackoverflow.com/a/12740518/6309 – VonC Aug 26 '14 at 14:36
  • If your LESS files aren't part of the source (only CSS), how do you then manage changes in LESS source between different developers? Or am I understanding your answer incorrectly? – pspahn Mar 12 '15 at 20:53
  • @pspahn the post-receive hook is not here to remove LESS files from the git repo, but to remove them from the target deployment folder (a production setting, where they are no longer needed after `lessc`): it is a release management process, not a development one. – VonC Mar 12 '15 at 21:00
  • I mistook "remove" as remove from the repo (which seems like it would be a hassle). – pspahn Mar 12 '15 at 21:15