Closed Shyam-Chen closed 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.
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
@TimMensch
Do you have examples of it?
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
changed
? It may not work to pipe through both. newer
line like I suggested to see if that worked? Given your code, you should also try removing the changed
line. You should do that anyway; the plugins do the same thing and may interfere with each other.And this:
gulp.task 'watch', ->
gulp watch
. Read this carefully: gulp.watch
doesn't run any code until it observes a file change after you run it. Your example was of gulp watch
, which won't run the code at all until you change something after you run gulp watch
. I'm 99% certain that's why it's "not working" for you, but you've made no mention of trying it, nor does your code show such a dependency.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.
Hi @TimMensch
I intend to remove gulp-newer
. (Reserved gulp-changed
)