Skip to content

Instantly share code, notes, and snippets.

@amir-rahnama
Last active July 16, 2018 14:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amir-rahnama/4f83b16f319911c82da6 to your computer and use it in GitHub Desktop.
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
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