-
-
Save serhiinkh/2af92489bbfb9e2bf1fe to your computer and use it in GitHub Desktop.
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
// --- INIT | |
var gulp = require('gulp'), | |
less = require('gulp-less'), // compiles less to CSS | |
minify = require('gulp-minify-css'), // minifies CSS | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), // minifies JS | |
rename = require('gulp-rename'), | |
browserSync = require('browser-sync'); | |
// Start the server | |
gulp.task('browser-sync', function() { | |
browserSync({ | |
server: { | |
baseDir: "./" | |
}, | |
open: false, | |
}); | |
}); | |
var paths = { | |
'dev': { | |
'less': './dev/less/', | |
'js': './dev/js/', | |
'vendor': './dev/vendor/' | |
}, | |
'assets': { | |
'css': './assets/css/', | |
'js': './assets/js/', | |
'vendor': './bower_vendor/' | |
} | |
}; | |
function swallowError(error) { | |
console.log(error.toString()); | |
this.emit('end'); | |
} | |
// --- TASKS | |
gulp.task('frontend.css', function() { | |
// place code for your default task here | |
return gulp.src(paths.dev.less+'frontend.less') // get file | |
.pipe(less()).on('error', swallowError) | |
.pipe(gulp.dest(paths.assets.css)) // output: frontend.css | |
.pipe(minify({keepSpecialComments:0})) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(paths.assets.css)) // output: frontend.min.css | |
.pipe(browserSync.reload({stream:true})); // reload browser | |
}); | |
gulp.task('frontend.js', function() { | |
return gulp.src([ | |
paths.assets.vendor+'jquery/dist/jquery.js', | |
paths.assets.vendor+'bootstrap/dist/js/bootstrap.js', | |
paths.dev.js+'frontend.js' | |
]) | |
.pipe(concat('frontend.min.js')) | |
.pipe(uglify()).on('error', swallowError) | |
.pipe(gulp.dest(paths.assets.js)) | |
.pipe(browserSync.reload({stream:true})); // reload browser | |
}); | |
// --- WATCH | |
//Rerun the task when a file changes | |
gulp.task('watch', ['browser-sync'], function() { | |
gulp.watch(paths.dev.less + '*.less', ['frontend.css', browserSync.reload]); | |
gulp.watch(paths.dev.js + '*.js', ['frontend.js', browserSync.reload]); | |
gulp.watch("*.html", browserSync.reload); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment