Last active
March 10, 2017 13:05
-
-
Save netsmertia/10690d68423a6e1add7f to your computer and use it in GitHub Desktop.
BasicGulpFile
This file contains 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
//Basic gulpfile.js with sass, jade, browser-sync and desktop notification | |
var gulp = require('gulp'); | |
var sass = require('gulp-sass'); | |
var rename = require('gulp-rename'); | |
var minifycss = require('gulp-minify-css'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var browserSync = require('browser-sync'); | |
var jade = require('gulp-jade'); | |
var data = require('gulp-data'); | |
var gutil = require('gulp-util'); | |
var notification = require('node-notifier'); | |
// display error and send notification | |
function logError(app, err) { | |
gutil.log(gutil.colors.red("\n"+err)); | |
(new notification).notify({message: app+" Error!!\n" + err}); | |
} | |
//start the server | |
gulp.task('browser-sync', function() { | |
browserSync({ | |
server: { | |
baseDir: './dist', | |
logLevel: 'debug' | |
} | |
}); | |
}); | |
//copy tasks | |
gulp.task('copy:fonts', function() { | |
return gulp.src(['bower_components/semantic-ui-sass/app/assets/fonts/semantic-ui/*']) | |
.pipe(gulp.dest('dist/fonts/')); | |
}); | |
gulp.task('copy:js', function() { | |
return gulp.src(['bower_components/semantic-ui-sass/app/assets/javascripts/semantic-ui/**/*', | |
'bower_components/jquery/dist/*.min.js' | |
]) | |
.pipe(gulp.dest('dist/js/')); | |
}); | |
gulp.task('style', function() { | |
return gulp.src('src/scss/*.scss') | |
.pipe(sass({ | |
includePaths: ['bower_components/semantic-ui-sass/app/assets/stylesheets'], | |
onError: function(err) { | |
logError("Sass", err); | |
} | |
})) | |
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) | |
.pipe(gulp.dest('dist/css')) | |
.pipe(browserSync.reload({stream: true})) | |
//.pipe(rename({suffix: '.min'})) | |
//.pipe(minifycss()) | |
//.pipe(gulp.dest('dist/css')); | |
}); | |
//gulp compile jade | |
gulp.task('jade', function() { | |
return gulp.src('src/jade/*.jade') | |
.pipe(data(function() { | |
return require('./src/jade/data.json'); | |
})) | |
.pipe( | |
jade({ pretty: true }) | |
.on('error', function(err){ | |
logError("Jade", err.message); | |
this.emit('end'); | |
}) | |
) | |
.pipe(gulp.dest('dist/')); | |
}); | |
gulp.task('copy', ['copy:fonts', 'copy:js']); | |
gulp.task('default', ['style', 'jade', 'browser-sync'], function() { | |
gulp.watch("src/scss/*.scss", ['style']); | |
gulp.watch("src/jade/{,*/}*.jade", ['jade']); | |
gulp.watch("dist/**/*.html", browserSync.reload); | |
gulp.watch("dist/js/**.js", browserSync.reload); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment