Last active
August 29, 2015 14:02
-
-
Save emolr/83889e49b44827ce2472 to your computer and use it in GitHub Desktop.
This file contains 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
# GULP.SRC() | |
The gulp.src() function takes a glob (i.e. a string matching one or more files) or an array of globs and returns a stream that can be piped to plugins. | |
Gulp uses node-glob to get the files from the glob or globs you specify. It’s easiest to explain using examples: | |
js/app.js | |
Matches the exact file | |
js/*.js | |
Matches all files ending in .js in the js directory only | |
js/**/*.js | |
Matches all files ending in .js in the js directory and all child directories | |
!js/app.js | |
Excludes js/app.js from the match, which is useful if you want to match all files in a directory except for a particular file | |
*.+(js|css) | |
Matches all files in the root directory ending in .js or .css | |
Multiply arguments | |
gulp.src(['js/**/*.js', '!js/**/*.min.js']) | |
# Running multiply tasks in gulp | |
A task may also be a list of other tasks. Suppose we want to define a build task that runs three other tasks, css, js and imgs. We can do this by specifying an array of tasks, instead of the function: | |
gulp.task('build', ['css', 'js', 'imgs']); | |
# Running tasks when other tasks has finished | |
gulp.task = greet will run first, and then css will run | |
gulp.task('css', ['greet'], function () { | |
// Deal with CSS here | |
}); | |
# Default Tasks | |
Will run when running just gulp | |
gulp.task('default', function () { | |
// Your default task | |
}); | |
# GULP-LOAD-PLUGINS | |
Gulp plugin which loads all plugins that are specified in the package.json | |
var gulp = require('gulp'), | |
gulpLoadPlugins = require('gulp-load-plugins'), | |
plugins = gulpLoadPlugins(); | |
gulp.task('minify', function () { | |
gulp.src('js/app.js') | |
.pipe(plugins.uglify()) | |
.pipe(gulp.dest('build/js')) | |
}); | |
# Examples from the article | |
//=========================================== | |
// GETTING STARTED | |
// (http://www.smashingmagazine.com/2014/06/11/building-with-gulp/) | |
//=========================================== | |
var gulp = require('gulp'), | |
gulpLoadPlugins = require('gulp-load-plugins'), | |
plugins = gulpLoadPlugins(); | |
gulp.task('minify', function () { | |
gulp.src('js/app.js') | |
.pipe(plugins.uglify()) | |
.pipe(gulp.dest('build/js')) | |
}); | |
gulp.task('js', function() { | |
gulp.src('js/*.js') | |
.pipe(plugins.jshint()) | |
.pipe(plugins.jshint.reporter('default')) | |
.pipe(plugins.concat('app.js')) | |
.pipe(plugins.uglify()) | |
.pipe(gulp.dest('build/js')) | |
}); | |
gulp.task('greet', function () { | |
console.log('Hello World'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment