Uglify

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 11 years ago
Updated 6 years ago

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

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.