Comments (12)
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.
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.
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.
Without a different destination, what is your proposal for being able to determine if the file is changed or unchanged?
from gulp-changed.
+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.
+1 for this
from gulp-changed.
+1
from gulp-changed.
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.
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.
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.
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.
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)
- when new files, it should be runing twice? HOT 4
- Run tests on newer node versions HOT 2
- not working with gulp-rename? HOT 6
- Question: Paths
- Convert tests to AVA
- Promisify the code
- SRC Variable - Array Capabilities
- changed.compareContents fails when directories are included HOT 1
- Unsure about this plugin HOT 2
- Typo on NPM page example. HOT 1
- Replace deprecated dependency gulp-util HOT 1
- it doesn't work with gulp-webpack。 HOT 1
- Compare with files with added hash HOT 2
- If `hasChanged` rejects (e.g. custom function) then an Unhandled Promise Rejection thrown
- compareLastModifiedTime does not work HOT 3
- compareLastModifiedTime with replaced files
- hasChanged function using Git log HOT 2
- Confused about when to use compareContents
- mtimeMs comparison is broken in node v14.17.0 HOT 4
- Area to ignore the adjustment HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-changed.