16.07.2017 Views

AngularJS Essentials

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8<br />

3. Concatenating step: The concatenation step, done by the grunt-contribconcat<br />

plugin, concatenates the configured source files inside a single<br />

destination file. This plugin can be installed with the following command:<br />

npm install grunt-contrib-concat --save-dev<br />

In order to configure it, we need to inform the source files and the destination<br />

file through the src and dest properties of the concat object, as follows:<br />

Gruntfile.js<br />

module.exports = function (grunt) {<br />

grunt.initConfig({<br />

clean: {<br />

dist: ["dist/"]<br />

},<br />

jshint: {<br />

dist: ['Gruntfile.js', 'js/**/*.js', 'test/**/*.js']<br />

},<br />

concat: {<br />

dist: {<br />

src: ["src/**/*.js"],<br />

dest: "dist/js/scripts.js"<br />

}<br />

}<br />

});<br />

grunt.loadNpmTasks("grunt-contrib-clean");<br />

grunt.loadNpmTasks("grunt-contrib-jshint");<br />

grunt.loadNpmTasks("grunt-contrib-concat");<br />

}<br />

grunt.registerTask("dist", ["clean", "jshint", "concat"]);<br />

4. Minifying step: Now, let's talk about the minifying step. As we mentioned<br />

before, it removes the white spaces, line breaks, comments, and replaces the<br />

names of the variables and functions. This can be done using the gruntcontrib-uglify<br />

plugin, which is installed using the following command:<br />

npm install grunt-contrib-uglify --save-dev<br />

The configuration is very similar to the grunt-contrib-concat plugin and<br />

involves the definition of the src and dest properties of the uglify object,<br />

as follows:<br />

Gruntfile.js<br />

module.exports = function (grunt) {<br />

[ 149 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!