Skip to content

Instantly share code, notes, and snippets.

@Meroje
Created September 12, 2014 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Meroje/3f3d8565562af7eaf50e to your computer and use it in GitHub Desktop.
Save Meroje/3f3d8565562af7eaf50e to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var less = require('gulp-less');
// Browser-sync task, only cares about compiled CSS
gulp.task('browser-sync', function() {
browserSync.init(["dist/**"], {
exclude: "dist/bower_components",
server: {
baseDir: "./dist"
}
});
});
// Sass task, will run when any SCSS files change.
gulp.task('sass', function () {
return gulp.src('src/scss/*.scss')
.pipe(sass({includePaths: [
'src/scss',
'dist/bower_components/foundation/scss',
'dist/bower_components/foundicons'
]}))
.pipe(gulp.dest('dist/css'));
});
// Less task, will run when any LESS files change.
gulp.task('less', function () {
return gulp.src('src/less/*.less')
.pipe(less())
.pipe(gulp.dest('dist/css'));
});
// Minify and copy all JavaScript (except vendor scripts)
gulp.task('scripts', function() {
return gulp.src('src/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
// Copy all static images
gulp.task('images', function() {
return gulp.src('src/img/**')
// Pass in options to the task
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest('dist/img'));
});
// Copy all static files
gulp.task('statics', function() {
// gulp.src(['src/{equipe,programme,contact}/*.html'])
// .pipe(gulp.dest('dist'));
return gulp.src(['src/**/*.html', 'src/**/*.txt', 'src/**/*.xml', 'src/**/*.pdf'])
.pipe(gulp.dest('dist'));
});
// Clean before deploying
gulp.task('clean', function() {
return gulp.src(['dist/css', 'dist/js', 'dist/img', 'dist/*.html', 'dist/*.txt', 'dist/*.xml'], {read: false})
.pipe(clean());
});
// Rerun the task when a file changes
gulp.task('watch-files', function () {
gulp.watch('src/**/*.html', ['statics']);
gulp.watch('src/**/*.txt', ['statics']);
gulp.watch('src/**/*.xml', ['statics']);
gulp.watch('src/**/*.pdf', ['statics']);
gulp.watch('src/js/**', ['scripts']);
gulp.watch('src/img/**', ['images']);
gulp.watch('src/scss/**', ['sass']);
gulp.watch('src/less/**', ['less']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['statics', 'scripts', 'images', 'less', 'sass']);
gulp.task('watch', ['statics', 'scripts', 'images', 'less', 'sass', 'browser-sync', 'watch-files']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment