$ [sudo] npm install -g grunt-cli
{
"name": "myGruntApp",
"version": "0.0.1",
"description": "",
"main": "index.js",
"author": "",
"license": "MIT"
}
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json')
});
};
concat: {
options: {
// define a string to put between each file in the
// concatenated output
separator: ';'
},
dist: {
// the files to concatenate
src: ['src/**/*.js'],
// the location of the resulting JS file
dest: 'dist/<%= pkg.name %>.js'
}
}
uglify: {
options: {
// the banner is inserted at the top of the output
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
}
}
}
qunit: {
files: ['test/**/*.html']
},
jshint: {
// define the files to lint
files: ['gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
// configure JSHint (documented at http://www.jshint.com/docs/)
options: {
// more options here if you want to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true
}
}
}
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
// this would be run by typing "grunt test" on the command line
grunt.registerTask('test', ['jshint', 'qunit']);
// the default task can be run just by typing "grunt" on the command line
grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);
Think about a stream where you start reading a file, apply operation to it and save it back to disk.
Grunt plug-ins often perform multiple tasks | Gulp plug-ins are designed to do one thing only. |
Grunt requires plug-ins for basic functionality such as file watching | Gulp has them built-in. |
Grunt uses JSON-like data configuration files | Gulp uses leaner, simpler JavaScript code. |
{
"name": "myGulpApp",
"version": "0.0.1",
"description": "",
"main": "index.js",
"author": "",
"license": "MIT"
}
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
var concat = require('gulp-concat');
gulp.task('scripts', function() {
gulp.src('./lib/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('./dist/'))
});
var uglify = require('gulp-uglify');
gulp.task('compress', function() {
gulp.src('lib/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist'))
});
var qunit = require('gulp-qunit');
gulp.task('test', function() {
return gulp.src('./qunit/test-runner.html')
.pipe(qunit());
});
var jshint = require('gulp-jshint');
gulp.task('lint', function() {
return gulp.src('./lib/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});