Last active
July 16, 2018 14:54
-
-
Save amir-rahnama/4f83b16f319911c82da6 to your computer and use it in GitHub Desktop.
Minimal gulpfile.js with Server, LiveReload and Watch Task for JS and Sass/Css
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
var gulp = require('gulp'), | |
jshint = require('gulp-jshint'), | |
connect = require('gulp-connect'), | |
livereload = require('gulp-livereload'), | |
paths = { | |
scripts: ['scripts/*.js'], | |
html: ['*/*.html'], | |
style_css: 'styles/css', | |
style_sass: 'styles/sass' | |
}, | |
LOCAL_SERVER_PORT = 4000; | |
gulp.task('server', function() { | |
connect.server({ | |
port: LOCAL_SERVER_PORT, | |
livereload: true | |
}); | |
}); | |
gulp.task('styles', function() { | |
gulp.src('./sass/**/*.scss') | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(gulp.dest('./css')); | |
}); | |
gulp.task('jshint', function() { | |
return gulp.src(paths.scripts) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')); | |
}); | |
gulp.task('watch', function() { | |
livereload.listen({ | |
start: true, | |
reloadPage: 'index.html' | |
}); | |
gulp.watch(paths.scripts + '*.js', ['scripts:watch']); | |
gulp.watch(paths.style_sass + '*.scss', ['sass:watch']); | |
}); | |
gulp.task('sass:watch', function() { | |
gulp.src('styles/sass/*.scss') | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(gulp.dest('styles/css')); | |
}); | |
gulp.task('scripts:watch', ['jshint'], function(event) { | |
gulp.src(paths.scripts) | |
.pipe(livereload()); | |
}); | |
gulp.task('dev', ['server', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment