JavaScript file concatenation

Just as we minified and concatenated our style sheets, we shall now go ahead and minify and concatenate our JavaScript files. Go ahead and take a look at grunt-contrib-uglify. Visit https://github.com/gruntjs/grunt-contrib-uglify for more.

Install this by typing:

sudo npm install grunt-contrib-uglify -save-dev

And, as always, enable it by adding grunt.loadNpmTasks('grunt-contrib-uglify'); to our Gruntfile.js. Next, create a new task:

    "uglify": {  
        "target": { 
            "files": { 
                "dist/src/js/myphoto.min.js": ["src/js/*.js"] 
            } 
        } 
    } 

Running grunt uglifyshould produce the following output:

JavaScript file concatenation

Figure 8.8: The console ...

Get Mastering Bootstrap 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.