Skip to content

Instantly share code, notes, and snippets.

@rpullinger
Created March 7, 2014 16:44
Show Gist options
  • Save rpullinger/9414989 to your computer and use it in GitHub Desktop.
Save rpullinger/9414989 to your computer and use it in GitHub Desktop.
Simple gulp starter
// Init npm if not already
npm init
// Install gulp and plugins
npm install gulp gulp-ruby-sass gulp-autoprefixer gulp-minify-css gulp-jshint gulp-uglify gulp-rename gulp-clean gulp-concat gulp-notify gulp-cache gulp-livereload tiny-lr --save
// Gulp!
gulp styles
gulp js
gulp watch
/*jslint node: true */
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr();
var locations = {
sass: 'sass/**/*.scss',
js: 'js/**/*.js',
assetsJS: 'web/js',
assetsCSS: 'web/css',
};
gulp.task('default', function(){});
gulp.task('styles', function() {
return gulp.src(locations.sass)
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest(locations.assetsCSS))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest(locations.assetsCSS))
.pipe(livereload(server));
});
gulp.task('scripts', function() {
return gulp.src(locations.js)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(gulp.dest(locations.assetsJS))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(locations.assetsJS))
.pipe(livereload(server));
});
gulp.task('watch', function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
// Watch .scss files
gulp.watch(locations.sass, function(event) {
gulp.run('styles');
});
// Watch .js files
gulp.watch(locations.js, function(event) {
gulp.run('scripts');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment