Gulp is the streaming build system. Gulp’s use of streams and code-over-configuration makes for a simpler and more intuitive build. I didn’t use Gulp or Grunt before. Today, I hear about it and decide to use it on my project. What I write here is not a tutorial, it just what I do with Gulp.
1. Install – NodeJS - Gulp:
To install Gulp we must have node installed. Nodejs can be installed from here http://nodejs.org/
– Gulp: We should install gulp globally
1 | $ npm install -g gulp |
2. Using Gulp in project First, jump to your project folder.
1 | $ cd /path/to/your/project |
Install gulp and gulp-util in your project as devDepencies. Before it you should have package.json file in your project or init it by
1 | npm init |
--save-dev will let npm add gulp and gulp-util into devDepencies of file package.json
Create file gulpfile.js at your project root with bellow simple content:
1 | var gulp = require('gulp'); |
Run gulp
1 | $ gulp |
3. Do more with gulp
Above is just some step to get started with gulp. You can find here https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md
I want do more with gulp in my project, such as minify JS code, build LESS code to CSS… Let install some gulp plugins and write some simple code. Gulp plugins can be found here: http://gratimax.github.io/search-gulp-plugins/
As my requirement I will install gulp-less, gulp-uglify and gulp-jshint.
1 | $ npm install --save-dev gulp-less gulp-uglify gulp-jshint |
Now, we create (make) some tasks for gulp by writing code.
1 | var gulp = require('gulp'); |
There are 4 gulp tasks and they can be called by commands:
1 | $ gulp jshint |
- Task
jshint: This task will check all JS file in folder/jsand report error. - Task
minify: This task will get all JS files in folder/js, minifies them and save to folder/dist/js - Task
less: This task will convert all LESS files in folder /less to CSS and save to folder/dist/css - Task
default: This task will run 3 above tasks and add watching for JS, LESS files. If JS files in folder/jschange, it will run task jshint and minify. The same with LESS file in folder/less.
Wrapping UP After all, we can:
- Install NodeJS
- Install Gulp and its plugins
- Create Gulp tasks for our project
This is the first time I using gulp, if you have any info or ideal about gulp feel free to comment and let me know. Very thank you for your comments.