GithubHelp home page GithubHelp logo

Comments (12)

plankguy avatar plankguy commented on May 12, 2024 1

As a work-around, i'm writing to a cache folder:

gulp.task('imagemin', function() {
    gulp.src( './images/**/*' )
        .pipe( plugins.changed( './.cache/imagemin' ) ) // check cache
        .pipe( plugins.imagemin( settings.imagemin ) )
        .pipe( gulp.dest( './.cache/imagemin' ) ) // write to cache
        .pipe( gulp.dest( './images' ) );
});

There's likely a more elegant solution, but this works for now!

from gulp-changed.

michaek avatar michaek commented on May 12, 2024

I think that's by design. The library works by comparing the mtime of two files to detect changes, and if it's comparing the mtime of a file against itself, it will always appear to be unchanged.

from gulp-changed.

LZ-TimHunold avatar LZ-TimHunold commented on May 12, 2024

It would be very useful to do this. For me, I have a staging server that gets files pushed to it and I wanted to add a task that will run things like uglify and csso to take the file and optimize itself.

from gulp-changed.

michaek avatar michaek commented on May 12, 2024

Without a different destination, what is your proposal for being able to determine if the file is changed or unchanged?

from gulp-changed.

plankguy avatar plankguy commented on May 12, 2024

+1 for this.

I'm using imagemin, and i'd like to only compress files that are changed, but do so in the same 'images' directory, rather than having to write to another directory.

As for implementation - write to a cache file that tracks the changes w/ mtime, then check the cache, rather than the src file as reference for changed/unchanged.

from gulp-changed.

red2678 avatar red2678 commented on May 12, 2024

+1 for this

from gulp-changed.

samIntegrateur avatar samIntegrateur commented on May 12, 2024

+1

from gulp-changed.

michaek avatar michaek commented on May 12, 2024

It seems like what you're looking for is just a custom hasChanged function. In the cases you're describing, you want to compare the file source file not against its destination (which is the same) but against the time of the last run. If the file is newer than the last run, return true from your hasChanged implementation, and that file will proceed through the stream for processing. I am almost certain this case isn't going to find its way into the library, and it's straightforward to make your own hasChanged.

from gulp-changed.

marcobiedermann avatar marcobiedermann commented on May 12, 2024

I am having the same problem. My idea is to create a hash database (plain json file) for all files and write a custom comparison function to lookup if hash already exists in db, if so skip the process.
It would be great to have such a feature build in. 👍

from gulp-changed.

svivian avatar svivian commented on May 12, 2024

Not working for me either. I'm using with with gulp-imagemin like this:

return gulp.src(dir + '/**')
	.pipe(imagemin(
		[imagemin.optipng(), imagemin.jpegtran(), imagemin.gifsicle()]
	))
	.pipe(changed(dir))
	.pipe(gulp.dest(dir));

It says gulp-imagemin: Minified 1 image (saved 288 B - 36.9%) but the file is not saved.

Maybe I'm misunderstanding something, but shouldn't it pick up that the files in the stream have been modified compared to the files on disk?

from gulp-changed.

weslley-campos avatar weslley-campos commented on May 12, 2024

Not working for me either. I'm using with with gulp-imagemin like this:

return gulp.src(dir + '/**')
	.pipe(imagemin(
		[imagemin.optipng(), imagemin.jpegtran(), imagemin.gifsicle()]
	))
	.pipe(changed(dir))
	.pipe(gulp.dest(dir));

It says gulp-imagemin: Minified 1 image (saved 288 B - 36.9%) but the file is not saved.

Maybe I'm misunderstanding something, but shouldn't it pick up that the files in the stream have been modified compared to the files on disk?

I am like the same problem, for this plugin to work the source needs to be different from the destination.
But I need them to be the same.

from gulp-changed.

sindresorhus avatar sindresorhus commented on May 12, 2024

Like @michaek said, this is by design. I would be happy to add more built-in comparator functions if someone can come up with a clever design though.

from gulp-changed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.