Article Image
read

Grunt is an awesome tool. I use it everyday and I cannot think of working without it. As time passed by, our Gruntfile.js file became really big, and managing this file has become a real bummer. Since Grunt's best practices recommend using one and only one Gruntfile.js per repository, the solution should be using smaller project's files and import it to the main Gruntfile.js using node.js export/require capabilities.

Let's get straight to the point. Assume we have two (very simple) projects, on the same repository, with the following Gruntfile.js:

While this is a super simple example, it demonstrates how a Gruntfile.js can become a very large file, very fast. Just imagine that you have 4-5 projects using ~10 Grunt plugins each. A real nightmare...

Node.js export / require to the rescue!

We will now create two files, project1.js and project2.js (I will demonstrate project1.js here. For this simple example project2.js is pretty much the same)

And now your Gruntfile.js will look something similar to this:

That's it! Your projects are now handled in different Grunt configuration files, which makes it much simpler to handle.

Blog Logo

Yaniv Efraim


Published

Image

Advanced Front End topics

Back to Overview