Last active
August 9, 2016 14:26
-
-
Save addyosmani/8640122 to your computer and use it in GitHub Desktop.
Gulp comparison examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
grunt.initConfig({ | |
concat: { | |
'dist/all.js': ['src/*.js'] | |
}, | |
uglify: { | |
'dist/all.min.js': ['dist/all.js'] | |
}, | |
jshint: { | |
files: ['gruntfile.js', 'src/*.js'] | |
}, | |
watch: { | |
files: ['<%= jshint.files =>'], | |
tasks: ['jshint', 'concat', 'uglify'] | |
} | |
}); | |
// Load Our Plugins | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
// Register Default Task | |
grunt.registerTask('default', ['jshint', 'concat', 'uglify']); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var jshint = require('gulp-jshint'); | |
var concat = require('gulp-concat'); | |
var rename = require('gulp-rename'); | |
var uglify = require('gulp-uglify'); | |
// Lint JS | |
gulp.task('lint', function() { | |
gulp.src('./src/*.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')); | |
}); | |
// Concat & Minify JS | |
gulp.task('minify', function(){ | |
gulp.src('./src/*.js') | |
.pipe(concat('all.js')) | |
.pipe(gulp.dest('./dist')) | |
.pipe(rename('all.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('./dist')); | |
}); | |
// Default | |
gulp.task('default', function(){ | |
gulp.run('lint', 'minify'); | |
// Watch JS Files | |
gulp.watch("./src/*.js", function(event){ | |
gulp.run('lint', 'minify'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include gulp | |
var gulp = require('gulp'); | |
// Include Our Plugins | |
var jshint = require('gulp-jshint'); | |
var sass = require('gulp-sass'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var rename = require('gulp-rename'); | |
// Lint Task | |
gulp.task('lint', function() { | |
gulp.src('./js/*.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')); | |
}); | |
// Compile Our Sass | |
gulp.task('sass', function() { | |
gulp.src('./scss/*.scss') | |
.pipe(sass()) | |
.pipe(gulp.dest('./css')); | |
}); | |
// Concatenate & Minify JS | |
gulp.task('scripts', function() { | |
gulp.src('./js/*.js') | |
.pipe(concat('all.js')) | |
.pipe(gulp.dest('./dist')) | |
.pipe(rename('all.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('./dist')); | |
}); | |
// Default Task | |
gulp.task('default', function(){ | |
gulp.run('lint', 'sass', 'scripts'); | |
// Watch For Changes To Our JS | |
gulp.watch('./js/*.js', function(){ | |
gulp.run('lint', 'scripts'); | |
}); | |
// Watch For Changes To Our SCSS | |
gulp.watch('./scss/*.scss', function(){ | |
gulp.run('sass'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment