Presented by Jeremy A. Cantu
Want to follow along?
Graduated in 2015 with a degree in Computer Science
at Dell
Streaming build system, using Node.js file manipulation to operate as an automated JavaScript task runner
Because repeating a process gets old, fast
Testing and Linting
===
Code Quality
Streamlined Build Systems
===
Development Quality
Minification and Concatenation
===
Better Code Delivery
Prerequisite: You must have Node.js installed on your machine to use Gulp
#1 - Install Gulp globally
$ npm install gulp -g
Intermediary Step - Initialization
$ npm init
#2 - Install Gulp to your project's 'node_modules' and save as a developer dependency
$ npm install gulp --save-dev
#3 - Create your gulpfile.js
// grab our gulp package
var gulp = require('gulp');
// declare a gulp task
gulp.task('default', function() {
// run task
});
Define your Gulp tasks with 'gulp.task'
gulp.task('name', ['dependencies'], function() {
// run task 'name' with dependencies
});
Point to the files in your application that you want to 'pipe' to a particular directory via 'gulp.dest' using 'gulp.src'
gulp.src('public/scripts/*.js').pipe(gulp.dest('dist'));
Monitor a grouping of files in your application, and run defined tasks using 'gulp.watch'
gulp.watch('source/scripts/*.js', ['lint']);
Install Gulp Eslint
$ npm install gulp-eslint --save-dev
Add tasks to gulpfile.js
var gulp = require('gulp');
var lint = require('gulp-eslint');
// linting task
gulp.task('lint', function() {
return gulp.src('source/scripts/*.js')
.pipe(lint({config: 'eslint.config.json'}))
.pipe(lint.format());
});
// watch task for changes
gulp.task('watch', function() {
gulp.watch('source/scripts/*.js', ['lint']);
});
Set default Gulp tasks and run
// default gulp tasks
gulp.task('default', ['watch'], function () {});
$ gulp
Install Gulp Packages
$ npm install gulp-concat gulp-rename gulp-imagemin --save-dev
Add tasks to gulpfile.js
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
// minifying scripts task
gulp.task('minify', function() {
return gulp.src('source/scripts/*.js')
.pipe(concat('bundled.js'))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/scripts'))
});
gulp.task('watch', function() {
gulp.watch('source/scripts/*.js', ['minify']);
});
Set default Gulp tasks and run
// default gulp tasks
gulp.task('default', ['watch'], function () {});
$ gulp
Let's refrain from repeating ourselves...
♪~ ᕕ(ᐛ)ᕗ