Last active
November 11, 2018 16:18
-
-
Save yukal/51cfaad343f012d1d84291e4899e5d30 to your computer and use it in GitHub Desktop.
gulp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize plugins | |
var gulp = require('gulp'), | |
plugins = require('gulp-load-plugins')(), | |
browserSync = require('browser-sync').create(), | |
src = './src', | |
dst = './dist', | |
// Output details of the error and continue the project | |
swallowError = function(error) { | |
console.log(error.toString()); | |
this.emit('end') | |
} | |
; | |
gulp.task('webserver', ['build'], function() { | |
return browserSync.init({ | |
server: {baseDir: dst}, | |
open: false | |
}); | |
}); | |
// Compile HTML | |
gulp.task('html', function() { | |
return gulp.src(src + '/template/*.jade') | |
.pipe(plugins.jade({pretty: true})) | |
.on('error', swallowError) | |
.pipe(gulp.dest(dst)); | |
}); | |
// Compile CSS | |
gulp.task('css', function() { | |
return gulp.src(src + '/assets/css/**/*.scss') | |
//.pipe(plugins.sass({outputStyle: 'compressed'})) | |
.pipe(plugins.sass()) | |
.on('error', plugins.sass.logError) | |
.pipe(plugins.rename({suffix: '.min'})) | |
.pipe(gulp.dest(dst + '/assets/css')); | |
}); | |
// Compile JS | |
gulp.task('js', function() { | |
return gulp.src(src + '/assets/js/*.js') | |
.pipe(plugins.rigger()) | |
.on('error', swallowError) | |
.pipe(plugins.rename({suffix: '.min'})) | |
.pipe(gulp.dest(dst + '/assets/js')); | |
}); | |
Compile CoffeeScript | |
gulp.task('coffee', function() { | |
return gulp.src(src + '/assets/coffee/**/*.coffee') | |
.pipe(plugins.coffee({bare: true})) | |
.pipe(plugins.uglify()) | |
.pipe(plugins.rename({suffix: '.min'})) | |
.pipe(gulp.dest(dst + '/assets/js')); | |
}); | |
// Build media files | |
gulp.task('media', function() { | |
return gulp.src(src + '/assets/media/_/**/*.*') | |
.pipe(gulp.dest(dst + '/assets/media')) | |
.on('error', swallowError) | |
&& gulp.src(src + '/assets/media/images/**/*.*') | |
.pipe(gulp.dest(dst + '/images')) | |
.on('error', swallowError) | |
; | |
}); | |
// Clear all the build files | |
gulp.task('clean', function () { | |
return gulp.src(dst, {read: false}) | |
.pipe(plugins.clean({force: true})) | |
.on('error', swallowError) | |
; | |
}); | |
// Make a build of the project. | |
// The "clean" task should be first! | |
gulp.task('build', ['clean'], function(){ | |
return gulp.start('media') | |
&& gulp.start('html') | |
&& gulp.start('css') | |
&& gulp.start('js') | |
; | |
}); | |
// Enable the watcher | |
gulp.task('watch', ['webserver'], function() { | |
return gulp.watch(src + '/template/**/*.jade', ['html']) | |
.on('change', browserSync.reload) | |
&& gulp.watch(src + '/assets/css/**/*.scss', ['css']) | |
.on('change', browserSync.reload) | |
&& gulp.watch(src + '/assets/js/**/*.js', ['js']) | |
.on('change', browserSync.reload) | |
; | |
}); | |
// Enable default task | |
gulp.task('default', ['watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great , thank you!