tschaub / gulp-newer

Pass through newer source files only
https://npmjs.org/package/gulp-newer
226 stars 24 forks source link

Not Working #40

Closed Shyam-Chen closed 8 years ago

Shyam-Chen commented 8 years ago
var gulp = require('gulp');
var newer = require('gulp-newer');
var imagemin = require('gulp-imagemin');
var runSequence = require('run-sequence');

var IMAGES_SRC = './src/images/**/*';
var IMAGES_DEST = './public/images';

gulp.task('optimize-images', function() {
  return gulp.src(IMAGES_SRC)
    .pipe(newer(IMAGES_DEST))
    .pipe(imagemin())
    .pipe(gulp.dest(IMAGES_DEST));
});

gulp.task('watch', function() {
  gulp.watch(IMAGES_SRC, ['optimize-images']);
});

gulp.task('go', (done) =>
  runSequence('optimize-images', 'watch', done)
);
$ gulp go

default

TimMensch commented 8 years ago

gulp watch won't run the task at all unless one of the watched files or folders changes. Try removing the "newer" line and see if gulp watch runs 'optimize-images'.

You need to either make the watch task depend on 'optimize-images' directly or run that task first and then add files to the folder.

This isn't a gulp-newer bug.

Shyam-Chen commented 8 years ago

Hi @TimMensch still does not work

optimize-images https://github.com/Shyam-Chen/Angular1Coffee-Starter-Kit/blob/master/gulpfile.coffee#L281

watch https://github.com/Shyam-Chen/Angular1Coffee-Starter-Kit/blob/master/gulpfile.coffee#L338

build https://github.com/Shyam-Chen/Angular1Coffee-Starter-Kit/blob/master/gulpfile.coffee#L315

start https://github.com/Shyam-Chen/Angular1Coffee-Starter-Kit/blob/master/gulpfile.coffee#L380

Shyam-Chen commented 8 years ago

@TimMensch

Do you have examples of it?

TimMensch commented 8 years ago

still does not work

gulp newer does work. What did you try that "didn't work"? What were the exact symptoms? Did you try everything I suggested? If so, at least one of those experiments should have been without gulp-newer. If it doesn't work without gulp-newer, then you're asking in the wrong place.

Do you have examples of it?

Examples of it working? Yes, I've tested it in my own projects multiple times, and there are usage examples in the README. And there is a full test suite. I even use it with gulp-image-optimization, which is another gulp imagemin wrapper:

gulp.task('host-images', [ 'host-rx-assets' ], function (cb) {
    gulp.src(paths.host_image_source)
        .pipe(newer(paths.host_images))
        .pipe(imageop(imageMinOptions))
        .pipe(gulp.dest(paths.host_images))
        .on('end', cb)
        .on('error', cb);
});

The project has 144 stars and has been used by probably 10s of thousands of people. It works, and it's naive to assume that it just doesn't work.

In your code:

gulp.task 'optimize-images', ->
  gulp
    .src IMAGES_SRC
    .pipe changed IMAGES_DEST
    .pipe newer IMAGES_DEST

And this:

gulp.task 'watch', ->

Looking at your code, you're using gulp as a task runner. May as well use grunt if you're going to do that. Gulp allows tasks to depend on others, like so:

gulp.task 'watch', [ 'optimize-images' ], ->

That's what "adding a dependency" would look like. This would make it run 'optimize-images' once before you run the gulp.watch. You'd want to add dependencies on all the rest as well.

To make it work like the rest of your gulpfile, though, you probably want the "watch" task down at the bottom, and you would want it to run "build" first, and then the "watch" task above (which you'd need to rename).

If someone offers you advice that you don't understand, then ask what it means. Don't just ignore what you don't understand and say "it still won't work" without trying suggestions that have been given and reporting back the results. It's disrespectful.

Shyam-Chen commented 8 years ago

Hi @TimMensch I intend to remove gulp-newer. (Reserved gulp-changed)