0

wonder if someone can help me solve my problem. I am new to gulp and have successfully created a gulp file that works how I want it to by following different guides online.

I am trying to add CSS minify and live reload. Wonder if someone can help me at all as everything I'm doing is not working :(

Here's my current file. Thanks in advance

// Include gulp
var gulp = require('gulp'); 

// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');

// Lint Task
gulp.task('lint', function() {
    return gulp.src('js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

// Compile Our Sass
gulp.task('sass', function() {
    return gulp.src('styles/*.scss')
        .pipe(sass())
        .pipe(gulp.dest(''));
});

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src('js/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

// Watch Files For Changes
gulp.task('watch', function() {
    gulp.watch('js/*.js', ['lint', 'scripts']);
    gulp.watch('styles/*.scss', ['sass']);
});

// Default Task
gulp.task('default', ['lint', 'sass', 'scripts', 'watch']);

// Include gulp
var gulp = require('gulp'); 

// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');

// Lint Task
gulp.task('lint', function() {
    return gulp.src('js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});



// Compile Our Sass
gulp.task('sass', function() {
    return gulp.src('styles/*.scss')
        .pipe(sass())
        .pipe(gulp.dest(''));
});

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src('js/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

// Watch Files For Changes
gulp.task('watch', function() {
    gulp.watch('js/*.js', ['lint', 'scripts']);
    gulp.watch('styles/*.scss', ['sass']);
});



gulp.task('default', ['lint', 'sass', 'scripts', 'watch']);

1 Answers1

0

Your gulpfile looks absolutely fine to me. You just need to run the watch task and you will have sass and lint working for you. In order to start watch task, from the same directory which has gulpfile.js, run the command gulp watch. Then whenever you will make changes to *.js or *.css files, you will have live reload working for you.

You will have to add live-reload task. Check this here: gulp live-reload

ashfaq.p
  • 5,379
  • 21
  • 35
  • Thanks for your comment. Gulp watch does work but I just have to refresh the browser manually for the changes to appear. I managed to get live reload to work with grunt and it felt like I had been missing out for all these years so would love for css Minify and live reload to work with gulp –  Feb 06 '16 at 11:19
  • I have updated my answer to help you configure live reload in watch task. – ashfaq.p Feb 06 '16 at 11:22