Skip to content

Commit f2e5e47

Browse files
committed
fix cache-changed bugs
1 parent fce6641 commit f2e5e47

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

Diff for: gulpfile.js

+30-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
var gulp = require('gulp');
99
var autoprefixer = require('gulp-autoprefixer');
10+
var cache = require('gulp-cached');
1011
var changed = require('gulp-changed');
1112
var concat = require('gulp-concat');
1213
var deleted = require('gulp-deleted');
@@ -165,6 +166,32 @@ gulp.task('scripts', function () {
165166
}));
166167
});
167168

169+
// images optimisation (only changed)
170+
gulp.task('images', function () {
171+
return gulp
172+
.src(pathPrefixer(paths.images.files, paths.dev))
173+
.pipe(gulpif(
174+
config.env === 'dev',
175+
cache('images'),
176+
changed(paths.build + paths.images.src, {hasChanged: changed.compareSha1Digest})
177+
))
178+
// .pipe(cache('images'))
179+
// .pipe(changed(paths.build))
180+
// .pipe(changed(paths.build + paths.images.src, {hasChanged: changed.compareSha1Digest}))
181+
.pipe(imagemin())
182+
.pipe(gulpif(
183+
config.env === 'dev',
184+
gulp.dest(paths.dev + paths.images.src),
185+
gulp.dest(paths.build + paths.images.src)
186+
))
187+
// .pipe(gulp.dest(paths.build + paths.images.src))
188+
.pipe(notify({
189+
onLast: true,
190+
message: 'IMAGES task SUCCESS!',
191+
icon: null
192+
}));
193+
});
194+
168195
// livereload for “static” files (.html, .php, .jade, …)
169196
gulp.task('static', function () {
170197
livereload.reload();
@@ -175,6 +202,7 @@ gulp.task('watch', function () {
175202
livereload.listen();
176203
gulp.watch(pathPrefixer(paths.styles.files, paths.dev), ['styles']);
177204
gulp.watch(pathPrefixer(paths.scripts.files, paths.dev), ['scripts']);
205+
gulp.watch(pathPrefixer(paths.images.files, paths.dev), ['images']);
178206
gulp.watch(pathPrefixer(paths.static.files, paths.dev), ['static']);
179207
});
180208

@@ -198,8 +226,8 @@ gulp.task('init-build', function () {
198226
gulp.task('copy', ['init-build'], function () {
199227
return gulp
200228
.src(pathPrefixer(paths.site, paths.dev))
201-
.pipe(deleted(paths.dev, paths.build, paths.site))
202-
.pipe(changed(paths.build))
229+
.pipe(deleted(paths.dev, paths.build, pathPrefixer(paths.site, paths.dev)))
230+
.pipe(changed(paths.build, {hasChanged: changed.compareSha1Digest}))
203231
.pipe(gulp.dest(paths.build))
204232
.pipe(notify({
205233
onLast: true,
@@ -208,20 +236,6 @@ gulp.task('copy', ['init-build'], function () {
208236
}));
209237
});
210238

211-
// images optimisation (only changed)
212-
gulp.task('images', function () {
213-
return gulp
214-
.src(pathPrefixer(paths.images.files, paths.dev))
215-
.pipe(changed(paths.build))
216-
.pipe(imagemin())
217-
.pipe(gulp.dest(paths.build + paths.images.src))
218-
.pipe(notify({
219-
onLast: true,
220-
message: 'IMAGES task SUCCESS!',
221-
icon: null
222-
}));
223-
});
224-
225239
// revision control for styles and scripts
226240
gulp.task('rev', function () {
227241
return gulp

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"del": "^1.1.1",
1313
"gulp": "^3.8.11",
1414
"gulp-autoprefixer": "^2.2.0",
15+
"gulp-cached": "^1.1.0",
1516
"gulp-changed": "^1.2.1",
1617
"gulp-concat": "^2.5.2",
1718
"gulp-deleted": "https://github.com/thierrymichel/gulp-deleted/tarball/e739a38767bba379324dff7c45d6ec975aa96642",

0 commit comments

Comments
 (0)