Skip to content

Instantly share code, notes, and snippets.

@ahmednuaman
Created July 9, 2014 18:28
Show Gist options
  • Select an option

  • Save ahmednuaman/8f11f288dfbf6684e94d to your computer and use it in GitHub Desktop.

Select an option

Save ahmednuaman/8f11f288dfbf6684e94d to your computer and use it in GitHub Desktop.
GULP Y U NO RUN IN SERIES
var compass = require('gulp-compass'),
concat = require('gulp-concat'),
cssmin = require('gulp-cssmin'),
gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
jscs = require('gulp-jscs'),
jshint = require('gulp-jshint'),
livereload = require('gulp-livereload'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
rimraf = require('rimraf'),
sha1 = require('sha1'),
uglify = require('gulp-uglify'),
distFolder,
jsFiles,
hash,
htmlFiles,
sassFiles;
hash = sha1((new Date()).getTime());
distFolder = './dist/';
jsFiles = [
'./*.js',
'./assets/js/*.js'
];
htmlFiles = [
'./*.html'
];
sassFiles = [
'./assets/sass/styles.sass'
];
gulp.task('clean', function (done) {
rimraf(distFolder, done);
});
gulp.task('compass', function () {
gulp.src(sassFiles)
.pipe(compass({
css: 'assets/css',
sass: 'assets/sass',
image: 'assets/images'
}))
.pipe(gulp.dest('assets/css'));
});
gulp.task('lint', function () {
gulp.src(jsFiles)
.pipe(jshint())
.pipe(jscs());
});
gulp.task('move', function () {
gulp.src('api/**/*')
.pipe(gulp.dest(distFolder + 'api'));
gulp.src('index.html')
.pipe(replace('app.js', hash + '.js'))
.pipe(replace('styles.css', hash + '.css'))
.pipe(
replace(
'assets/vendor/bootstrap/dist/css/bootstrap.css',
'//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'
)
)
.pipe(
replace(
'assets/vendor/bootstrap/dist/js/bootstrap.min.js',
'//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'
)
)
.pipe(
replace(
'assets/vendor/jquery/dist/jquery.min.js',
'//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
)
)
.pipe(gulp.dest(distFolder));
});
gulp.task('minify', function () {
gulp.src('assets/css/*.css')
.pipe(concat('styles.css'))
.pipe(cssmin())
.pipe(rename(hash + '.css'))
.pipe(gulp.dest(distFolder + 'assets/css'));
gulp.src('assets/img/*.{png,gif,jpg}')
.pipe(imagemin())
.pipe(gulp.dest(distFolder + 'assets/img'));
gulp.src('assets/js/*.js')
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(rename(hash + '.js'))
.pipe(gulp.dest(distFolder + 'assets/js'));
});
gulp.task('watch', function () {
livereload.listen();
gulp.watch([
htmlFiles,
jsFiles,
'assets/css/*.css'
])
.on('change', livereload.changed);
gulp.watch(jsFiles, [
'lint'
]);
gulp.watch(sassFiles, [
'compass'
]);
});
gulp.task('default', [
'watch'
]);
gulp.task('build', [
'clean',
'compass',
'lint',
'minify',
'move'
]);
@ahmednuaman
Copy link
Copy Markdown
Author

Hmmm, gulpjs/gulp#426 (comment)

I was looking for something like gulp.start, but in the end I just use run-sequence instead. It does what I want, just slightly annoyed that there's no way to specify directly in gulp whether tasks should be concurrent or series, whereas you can in Grunt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment