This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Uglify

1:41 JavaScript lesson by

In this lesson John will show you how to start using Grunt Uglify to compress your javascript for production deployment.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

In this lesson John will show you how to start using Grunt Uglify to compress your javascript for production deployment.

Avatar
Seneca

It would be nice to know more specifically about how uglify treats its subproperties. You chose "dist" and then "files". How does uglify go about parsing that? If you called instead called "dist", "foo", would it behave the same way?

I'm assuming "files" is a reserved word that uglify recognizes. It would be nice if that was clarified. Thanks,

In reply to egghead.io

John Lindquist: Before we bring together all the watching, configuring, templating, and things like together, let's look at one more NPM task we want to install.

We want to do grunt-contrib-uglify. This one is going to download and install Uglify, which is used to concatenate and minify your files. We're going to keep it really basic here.

With Grunt, we want to load an NPM task of grunt-contrib-uglify, and then we're going to need a few files to uglify. We will create some JavaScript files. An app directory, and then I'll set up this dummy file, file one, file two, and file three.

Let's concatenate all these together, one, two, and three, into a minified version by configuring Uglify. We'll say Uglify, and then we need a target. We'll call this target-dist for "distribution, distributable." We need some files. We'll just go ahead and map the minified file, which can be dist/app.min.js, to the files we want to load in, which are going to be app and then every JavaScript file inside of app.

Once we run this, we can say grunt-uglify. Hit Enter. You can see. It says, "app.min.js was created."

We come up here, and we can see that we have app.min.js. We've just concatenated all of our files -- one, obviously alphabetically, three, and two.

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