You don't need Grunt

Datetime:2016-08-23 02:46:17          Topic: Grunt           Share

You don’t need Grunt

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 now?

I will not ask you to move back on 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 Makefile’s version is straight forward:

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:

Using Make:

Concatenate and Uglify Javascript files

For this one I recommend using Grunt, it makes life much easier sometimes :)

One more thing about Makefiles

To have environment dependent variables in your build setup. It’s possible to achieve this with following Makefile:

It’s possible to overwrite “SERVER_URL” easily when on production:

$ make echo_server
$ export SERVER_URL=''
$ 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.

About List