Java Reference
In-Depth Information
}
}
A Grunt file is then needed to create a custom task. This contains all the configuration for
the task to be completed and is always saved as Gruntfile.js. The following example shows
a Grunt file that can be used to create a default task; this will minify any JavaScript files in
the src folder and output the minified files into the js folder.
It uses the
uglify plugin
to minify the code. All Grunt files are placed inside a wrapper
function that uses the CommonJS Module
exports
syntax:
module.exports = function(grunt) {
// configuration goes at the start
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
build: {
src: 'src/*.js', // where to find the JavaScript
files to
↵
minify
dest: 'js/' // where to put the minified files
}
}
// These methods will load and register the tasks to do
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('default', ['uglify']);
};
To run the default task, simply enter the following command in a terminal:
grunt
Gulp
ularity. gulp also requires Node.js to run and is installed using npm. It also has its own plu-
gin system, although there are fewer plugins available than for Grunt.
