gulp.task('usemin', function () {
return gulp.src(path.src + '*.html')
.pipe(usemin({
assetsDir: 'src',
css: [ minifyCss(), 'concat', rev()],
js: [uglify(), rev()],
images: [rev()]
}))
.pipe(gulp.dest(path.dist));
});
It does not work on the images.
js, first declare the dependencies as shown in the following code. var gulp = require('gulp'); var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); var minify = require('gulp-minify-css'); Next, you need to create tasks for optimizing CSS and JavaScript as shown in the following code. gulp.
Static asset revisioning with dependency considerations, appends content hash to each filename (eg. unicorn. css => unicorn.
src() is given a glob to read from the file system and produces a Node stream. It locates all matching files and reads them into memory to pass through the stream. The stream produced by src() should be returned from a task to signal async completion, as mentioned in Creating Tasks.
The philosophy of gulp-rev-all is to me a good way to see asset revisioning. It's very well explained in their Readme that the hash should also take into account the reference(s) between revisioned files.
I've mocked up a little example that minify an image and a css file which use a background url
property to see the revision of the new image path.
gulp.task('image', function () {
return gulp.src('image.jpeg')
.pipe(img({ progressive: false }))
.pipe(gulp.dest('tmp'));
});
gulp.task('css', function () {
return gulp.src('test.css')
.pipe(css())
.pipe(gulp.dest('tmp'));
});
gulp.task('rev', ['image', 'css'], function () {
return gulp.src('tmp/**')
.pipe(rev())
.pipe(gulp.dest('dist'));
});
I've removed all the fancy stuff to be more clear, but you can see the whole example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With