@@ -80,12 +80,56 @@ gulp.task('default', gulp.series('clean', 'all'));
8080
8181## Incremental Builds
8282
83- We recommend these plugins:
83+ You can filter out unchanged files between runs of a task using
84+ the ` gulp.src ` function's ` since ` option and ` gulp.lastRun ` :
85+ ``` js
86+ gulp .task (' images' , function () {
87+ return gulp .src (paths .images , {since: gulp .lastRun (' images' )})
88+ .pipe (imagemin ({optimizationLevel: 5 }))
89+ .pipe (gulp .dest (' build/img' ));
90+ });
91+
92+ gulp .task (' watch' , function () {
93+ gulp .watch (paths .images , ' images' );
94+ });
95+ ```
96+ Task run times are saved in memory and are lost when gulp exits. It will only
97+ save time during the ` watch ` task when running the ` images ` task
98+ for a second time.
8499
85- - [ gulp-changed] ( https://github.com/sindresorhus/gulp-changed ) - only pass through changed files
86- - [ gulp-cached] ( https://github.com/contra/gulp-cached ) - in-memory file cache, not for operation on sets of files
87- - [ gulp-remember] ( https://github.com/ahaurw01/gulp-remember ) - pairs nicely with gulp-cached
88- - [ gulp-newer] ( https://github.com/tschaub/gulp-newer ) - pass through newer source files only, supports many:1 source: dest
100+ If you want to compare modification time between files instead, we recommend these plugins:
101+ - [ gulp-changed] ;
102+ - or [ gulp-newer] - supports many:1 source: dest .
103+
104+ [ gulp-newer] example:
105+ ``` js
106+ gulp .task (' images' , function () {
107+ var dest = ' build/img' ;
108+ return gulp .src (paths .images )
109+ .pipe (newer (dest)) // pass through newer images only
110+ .pipe (imagemin ({optimizationLevel: 5 }))
111+ .pipe (gulp .dest (dest));
112+ });
113+ ```
114+
115+ If you can't simply filter out unchanged files, but need them in a later phase
116+ of the stream, we recommend these plugins:
117+ - [ gulp-cached] - in-memory file cache, not for operation on sets of files
118+ - [ gulp-remember] - pairs nicely with gulp-cached
119+
120+ [ gulp-remember] example:
121+ ``` js
122+ gulp .task (' scripts' , function () {
123+ return gulp .src (scriptsGlob)
124+ .pipe (cache (' scripts' )) // only pass through changed files
125+ .pipe (header (' (function () {' )) // do special things to the changed files...
126+ .pipe (footer (' })();' )) // for example,
127+ // add a simple module wrap to each file
128+ .pipe (remember (' scripts' )) // add back all files to the stream
129+ .pipe (concat (' app.js' )) // do things that require all files
130+ .pipe (gulp .dest (' public/' ))
131+ });
132+ ```
89133
90134## Want to test the latest and greatest?
91135
@@ -135,3 +179,8 @@ Become a sponsor to get your logo on our README on Github.
135179
136180[ backers-image ] : https://opencollective.com/gulpjs/backers.svg
137181[ sponsors-image ] : https://opencollective.com/gulpjs/sponsors.svg
182+
183+ [ gulp-cached ] : https://github.com/contra/gulp-cached
184+ [ gulp-remember ] : https://github.com/ahaurw01/gulp-remember
185+ [ gulp-changed ] : https://github.com/sindresorhus/gulp-changed
186+ [ gulp-newer ] : https://github.com/tschaub/gulp-newer
0 commit comments