Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 829 of the free egghead.io lessons, plus get Angular 1.x content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Angular Automation: Introduction to Gulp

4:26 Angular 1.x lesson by

Angular projects require automation. Period.

In this series we will take a look at Gulp. Gulp is a task runner. It is the commander of our army of helper robots that take critical, yet totally mundane, tasks and perform them hundreds of times per day so we don't have to. When we sit down to work, we want to enter a single command, and then spend the rest of our day writing code, testing, and basically not thinking about how it is all glued together in the background.

Automation is critical to any project of significant size. We will start with the Eggly Bookmarks application, and develop proper build automation that will include production ready tools that you can start using in your applications today!


egghead.io comment guidelines

Avatar
egghead.io

Angular projects require automation. Period.

In this series we will take a look at Gulp. Gulp is a task runner. It is the commander of our army of helper robots that take critical, yet totally mundane, tasks and perform them hundreds of times per day so we don't have to. When we sit down to work, we want to enter a single command, and then spend the rest of our day writing code, testing, and basically not thinking about how it is all glued together in the background.

Automation is critical to any project of significant size. We will start with the Eggly Bookmarks application, and develop proper build automation that will include production ready tools that you can start using in your applications today!

Avatar
Vivek

Thanks for starting this series, It would be very helpful if you can also show the best way to add (or how to add) jquery and custom javascript files to your project using gulp.

Avatar
David

I would actually use bower for that.

If you mean how to automatically include them, well there are several ways to do that, actually.

gulp-usmin, gulp-inject, wiredep, all kinds of options, but it depends on your specific goal.

In reply to Vivek
Avatar
Andreas

looking forward to learn everything you showed in the second part. when are the parts coming?

In reply to egghead.io

Hello. Lukas Ruebbelke here. Welcome to the new series, where we are going to introduce build automation with Gulp. Gulp is a task runner, but I prefer to think of it as a commander of an army of robot helpers that take critical yet totally mundane tasks and perform them hundreds of times per day so we do not have to.

This frees us up to focus on the important things, like writing code, testing, and basically not thinking about the tedium of having to package things up and ship it out the door. Automation is absolutely critical to any project of significant size.

In this series, we will start by adding Gulp to the Eggly bookmarks application and then systematically add tasks so that by the time we are finished, we will have accomplished a few goals, the first goal being that changes to our source files will automatically be detected and a new build will be kicked off each time.

This will include compiling our less into CSS, running JSHint to catch any Javascript errors that we may have incurred, compiling our HTML partials into a single Javascript file, injecting the proper resources into our index.html file, and then serving that build up with express and nodemon.

We will take this a step further, when we want to kick off a production build, by concatenating our source files and then minifying and uglifying them, all the while keeping things safe by using ng-annotate. Let me give you just a quick demo to show you what we will end up with by the time we wrap us this series.

We have the Eggly bookmark manager here. Let's take a quick look at the index.html file. You can see that we actually do not have a reference to a CSS file or any local Javascript files. All we have here in its place is these inject blocks. Notice that our styles are in less, in the less directory, and our templates are in the appropriate feature directory.

Now I'm going to go up here and delete the bin and build directory. Then I'm going to hop into the command line and type "gulp." You can see that some various tasks ran. We are serving the project on port 3444.

If I click up here, you can see that there is indeed now a build directory. We have injected a CSS file into the head of this page. Then, if we go down, we have a list of resources that we need to actually run Eggly.

If we go into our app directory, we can see here that we've actually taken our HTML templates, converted them into strings, and then put them into our template cache as a loading optimization. We can also go into the browser. If we pull up the site on this port, you can see that it is running using express.

Speaking of which, if I go back into here, let me just pull up this Javascript file here. Let me just do something silly, like take out a semicolon. You can see that the build was automatically kicked off, but if I scroll up here, I got an error or a prompt telling me that I was missing the semicolon. I'll go ahead and put this back. It automatically picks up on that change and kicks off a new build.

Let's do one other thing real quick. If I go "gulp compile," it's going to kick off a production build. It's going to run all of the build tasks that we use to do the development build, but it's going to take it a step further by creating a single, concatenated Javascript file for us to work with.

Gulp is so powerful. The possibilities of the things that you can do in your application and the work that it can do for you is just about endless. It's just a phenomenal tool. I look forward to working through these in this series with you. I'll see you in the next lesson.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?