Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Started with Gulp.js

Getting Started with Gulp.js

Casey Zumwalt

March 05, 2014
Tweet

Other Decks in Technology

Transcript

  1. Install Gulp locally 4 ➜ project npm init npm init

    creates a package.json file in our project directory.
  2. Install Gulp locally 4 ➜ project npm install --save-dev gulp

    —save-dev instructs npm to add the dependence to the package.json file we created earlier.
  3. Setting up our Gulpfile 5 WHAT WE NEED GULP TO

    DO Lint and concatenate our JavaScript Compile our Sass files Minify and rename everything Reload our browser after each change
  4. Setting up our Gulpfile 5 ➜ project npm install gulp-jshint

    gulp-sass gulp-concat gulp-uglify gulp-rename gulp-livereload --save-dev
  5. gulpfile.js // Include gulp var gulp = require('gulp'), ! //

    Include Our Plugins jshint = require('gulp-jshint’), sass = require(‘gulp-sass'), concat = require(‘gulp-concat’), uglify = require(‘gulp-uglify'), rename = require(‘gulp-rename’); livereload = require(‘gulp-livereload'); Set up Gulp includes
  6. gulpfile.js // Compile Our Sass gulp.task('sass', function() { return gulp.src('scss/*.scss')

    .pipe(sass()) .pipe(gulp.dest('css')); }); Set up the Sass task
  7. gulpfile.js // Concatenate & Minify JS gulp.task('scripts', function() { return

    gulp.src('js/*.js') .pipe(concat('main.js')) .pipe(gulp.dest('js')) .pipe(rename('main.min.js')) .pipe(uglify()) .pipe(gulp.dest('js')); }); Concatenate and Minify the JS
  8. gulpfile.js gulp.task('watch', function() { server.listen(35729, function (err) { if (err)

    { return console.log(err) }; ! // Watch .scss files gulp.watch('scss/**/*.scss', ['sass']); ! // Watch .js files gulp.watch('js/**/*.js', ['scripts']); ! }); }); Watch the files and reload the browser when changed