Gulpfile.js for vanilla AngularJS projects

Since I’ve learnt Angular, most of my front-end web applications are written in it. Its brilliant. Everything works fine, up to a point where your application has grown 10 times the size it was since you started it. At some point you’d want something to accelerate your delivery. That’s when gulp comes in.

Gulp is kinda like a build tool but for javascript based applications. It runs on Node.js and is available on npm. All you need to do is:

or if you are using a unix based application:

That gets you access to the gulp command line. Once you have gulp installed, you need to something that tells it what to do with your project. Unlike many other build tools, gulp favours code over configuration. This means that rather than writing XML or YAML files that define the tasks, you write code. This is what makes gulp unique.

So, here’s what I have. Below is my gulpfile.js that I use in most of my AngularJS projects:

Most of my AngularJS code resides in public/app directory and hence you’ll see that in multiple places in that file.

A quick glance should tell you that this minifies all of my AngularJS code and combines it all in one big file called bundle.min.js which is then placed in public/dist folder. My HTML page is configured to only reference bundle.min.js.

When executed normally, it doesn’t minify the code because it assumes that the javascript code is being used for development. However, when I run gulp --type production it minifies the code and doesn’t write sourcemaps.

You can install all of this by running:

Oh and here’s my package.json:


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.