Link to home
Start Free TrialLog in
Avatar of Leo Torres
Leo TorresFlag for United States of America

asked on

Gulp not seeing Changes

Here is my entire gulp file. Its does not have any syntax errors because it does not error and the index.html page does get severed.

My issue is that gulp is used to automatically re-process all files if they have been changed and reserve them with new updates. Well I am not getting that action.

All the files I am changing are in the app folder and app\script folders js files and html files. But when I edit these files I am not getting a recompilation done. I have to stop gulp process and start it again to get a new build What am i doing wrong. Code is below please advise and thanks in advance.
   

var gulp = require('gulp'),
    minifycss = require('gulp-minify-css'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    uglify = require('gulp-uglify'),
    usemin = require('gulp-usemin'),
    imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    changed = require('gulp-changed'),
    rev = require('gulp-rev'),
    browserSync = require('browser-sync'),
    ngannotate = require('gulp-ng-annotate'),
    del = require('del');

gulp.task('jshint', function() {
  return gulp.src('app/scripts/**/*.js')
  .pipe(jshint())
  .pipe(jshint.reporter(stylish));
});

gulp.task('usemin',['jshint'], function () {
  return gulp.src('./app/**/*.html')
    .pipe(usemin({
      css:[minifycss(),rev()],
      js: [ngannotate(),uglify(),rev()]
    }))
    
    .pipe(gulp.dest('dist/'));
});


// Images
gulp.task('imagemin', function() {
  return del(['dist/images']), gulp.src('app/images/**/*')
    .pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
    .pipe(gulp.dest('dist/images'))
    .pipe(notify({ message: 'Images task complete' }));
});

// Clean
gulp.task('clean', function() {
    return del(['dist']);
});

gulp.task('copyfonts', ['clean'], function() {
   gulp.src('./bower_components/font-awesome/fonts/**/*.{ttf,woff,eof,svg}*')
   .pipe(gulp.dest('./dist/fonts'));
   gulp.src('./bower_components/bootstrap/dist/fonts/**/*.{ttf,woff,eof,svg}*')
   .pipe(gulp.dest('./dist/fonts'));
});

// Watch
gulp.task('watch', ['browser-sync'], function() {

    // Watch .js files
  gulp.watch('{app/scripts/**/*.js,app/styles/**/*.css,app/**/*.html,app/scripts/*.js}', ['usemin']);

    // Watch image files
  gulp.watch('app/images/**/*', ['imagemin']);

});

gulp.task('browser-sync', ['default'], function () {
    var files = [
      'app/**',
      'app/**/*.html',
      'app/styles/**/*.css',
      'app/images/**/*.png',
      'app/scripts/**/*.js',
      'app/scripts/*.js',
      'dist/**/*'
   ];

   browserSync.init(files, {
      server: {
         baseDir: "dist",
         index: "index.html"//"ContactUs.html"//"menu.html"
      }
   });

    // Watch any files in dist/, reload on change
  gulp.watch(['dist/**']).on('change', browserSync.reload);
    });


// Default task
gulp.task('default', ['clean'], function() {
    gulp.start('usemin', 'imagemin','copyfonts','browser-sync');
});

/*
gulp.task('move-dist', function () {
    return gulp.src([
        './conFusion/dist/**'
    ], { base: './Week4/' })
    .pipe(gulp.dest('./json-server/public/'))
})
*/

gulp.task('copy-dist', function () {
    gulp.src('./conFusion/dist/**')
    // Perform minification tasks, etc here
    .pipe(gulp.dest('./json-server/public/'));
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leo Torres

ASKER

Well you may be write all this does is create my dist folder on initial run after that it does nothing when I change files.
I don't know how far you have gotten so far, but I presume that my post was not helpful enough.

The normal usage of a watch is to rebuild the project and reload it in a browser. This tutorial might help you.
https://www.smashingmagazine.com/2014/06/building-with-gulp/

Now back to your gulp file. There are several watches, but what task do you use to start the browser and watch?
haven't had a chance to try.