npm install -g grunt-cli
npm install grunt --save-dev
npm init
{
"name": "my-project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0"
}
}
npm install
npm install <module> --save-dev
module.exports = function(grunt) {
// Add configuration, tasks and plugins here
};
grunt.initConfig({
// imports the config data from the package.json
pkg: grunt.file.readJSON('package.json'),
task: {
// Add task here
},
task: {
// Add another task here
}
});
These need to be specified in your package.json file and installed using npm install. You will get an error when trying to run without installing a plugin.
// Load the Grunt plugins.
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
Used to specify a default set of tasks that should run when the grunt command is executed.
// Register the default tasks.
grunt.registerTask('default', ['watch']);
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['uglify']);
};