Gulp is a JavaScript build system, node.js-based task runner like Grunt. It allows you to automate common tasks during your development process. Gulp uses the streams-concept and code-over-configuration for a simpler and more intuitive build process. The code-over-configuration concept allows to create more readable and simple tasks, whereas grunt tasks are highly over-configured.
Version | Release date |
---|---|
3.4 | 2014-01-17 |
3.7 | 2014-06-01 |
3.8 | 2014-06-10 |
3.9 | 2015-06-02 |
3.9.1 | 2016-02-09 |
4.0.0 | 2016-06-21 |
var gulp = require('gulp');
// include plug-ins
var uglify = require('gulp-uglify'),
concat = require('gulp-concat');
// Minified file
gulp.task('packjsMin', function() {
return gulp.src('node_modules/angular/*.js')
.pipe(concat('script.js'))
.pipe(uglify())
.pipe(gulp.dest('Scripts'));
});
//Not minified file
gulp.task('packjs', function () {
return gulp.src('node_modules/angular/*.js')
.pipe(concat('allPackages.js'))
.pipe(gulp.dest('Scripts'));
});
gulp has very few flags to know about. All other flags are for tasks to use if needed.
-v
or --version
will display the global and local gulp versions--require <module path>
will require a module before running the gulpfile. This is useful for transpilers but also has other applications. You can use multiple --require
flags--gulpfile <gulpfile path>
will manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well--cwd <dir path>
will manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here-T
or --tasks
will display the task dependency tree for the loaded gulpfile--tasks-simple
will display a plaintext list of tasks for the loaded gulpfile--color
will force gulp and gulp plugins to display colors even when no color support is detected--no-color
will force gulp and gulp plugins to not display colors even when color support is detected--silent
will disable all gulp loggingThe CLI adds process.env.INIT_CWD which is the original cwd it was launched from.
Refer to this StackOverflow link for how to add task specific flags
Tasks can be executed by running gulp <task> <othertask>
. Just running gulp
will execute the task you registered called default
. If there is no default
task gulp will error.
You can find a list of supported languages at interpret. If you would like to add support for a new language send pull request/open issues there.
Gulp requires Node.js and NPM, Node's package manager. Most installers include NPM with Node.js. Refer to the installation documentation or confirm it is already installed by running the following command in your terminal,
npm -v
// will return NPM version or error saying command not found
If you have previously installed a version of gulp globally, please run npm rm --global gulp
to make sure your old version doesn't collide with gulp-cli.
$ npm install --global gulp-cli
$ npm init
$ npm install --save-dev gulp
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
$ gulp
The default task will run and do nothing.
To run individual tasks, use gulp <task> <othertask>
.
You can run tasks in series, by passing a second parameter to gulp.task()
.
This parameters is an array of tasks to be executed and completed before your task will run:
var gulp = require('gulp');
gulp.task('one', function() {
// compile sass css
});
gulp.task('two', function() {
// compile coffeescript
});
// task three will execute only after tasks one and two have been completed
// note that task one and two run in parallel and order is not guaranteed
gulp.task('three', ['one', 'two'], function() {
// concat css and js
});
// task four will execute only after task three is completed
gulp.task('four', ['three'], function() {
// save bundle to dist folder
});
You can also omit the function if you only want to run a bundle of dependency tasks:
gulp.task('build', ['array', 'of', 'task', 'names']);
Note: The tasks will run in parallel (all at once), so don't assume that the tasks will start/finish in order. Starting gulp v4, gulp.series()
should be used if the order of execution of dependency tasks is important.