Don’t get me wrong, grunt (and his little cousin gulp) are great tool, with them it has been made possible to ease development and deployment of (nearly) every recent application, in just a matter of configuration copy-pasting and variable replacing, your project build setup is ready. In fact it’s so easy that we don’t remember how we were doing before. Let me tell you.
No need to beat around the bush, because you already know it, we were building our project manually, by running a bash script who takes care of each and ever step, and voilà, project is ready to be deployed. So, what?
I will not ask you to move back to bash scripts, because we want benefits of both worlds, speed of bash scripts and flexibility of grunt. So let’s leave frontend wonderland to land in unix hell (just kinding). Here we are. What do you see? … I see Makefiles.
Compiling CSS files
Following grunt config is a bit verbose but still easy to understand:
On the other hand here is Makefile’s version:
Principal benefit from this method, other than simplicity, is speed, because lessc is a C++ library compiling CSS more than 10 times faster than its node equivalent.
Watch for changes
One of my favorite feature is to be able to watch files for change:
Using node watchy we can achieve the same result:
An awesome feature of Makefiles is to be able to invoke “css” target using “make css” inside the watch, DRY code.
Live reloading files
Live reload your files can help to improve productivity, you can enable it in Grunt with:
For this one I recommend using Grunt, it makes life much easier sometimes :)
One more thing about Makefiles
You might want to use a different configuration on production. To have environment dependent variables in your build setup. It’s possible to achieve this with following Makefile:
It’s now possible to overwrite “SERVER_URL” easily on production:
$ make echo_server
http://webiste.dev$ export SERVER_URL='https://website.com'
$ make echo_server
To conclude, we should not drop Grunt in every project in favor of Makefiles, but let be true with ourself and agree that a good old Makefile is sometimes the best choice when starting a small project.
Thanks for reading.