gulp-read
v1.0.1
Published
Gulp plugin to read vinyl file contents
Downloads
2,720
Maintainers
Readme
gulp-read
Gulp plugin to read vinyl file contents.
Installation
npm install --save-dev gulp-read
Usage
Basically whenever you can get away with using read:false
at the beginning of a stream, but you still need the file contents at a later stage. Here's what a typical example might look like:
var gulp = require('gulp');
var changed = require('gulp-changed');
var read = require('gulp-read');
var imagemin = require('gulp-imagemin');
var remember = require('gulp-remember');
gulp.task('image', function() {
return gulp.src('images/**', {read:false})
.pipe(changed('dist/images'))
.pipe(read())
.pipe(imagemin())
.pipe(remember())
.pipe(gulp.dest('dist/images'));
});
In the above we don't have to read file contents initially since all gulp-changed
cares about is the last modification date of each file.
After the unchanged files have been removed from the stream the contents of the remaining files are then read by gulp-read
so they can be processed by gulp-imagemin
.
In effect we never have to read the contents of files that haven't changed which saves time and speeds up the build.
Compatibiliy
Since this plugin is basically identical to the get-contents
module of vinyl-fs
it shouldn't make a difference whether file contents are read by gulp.src()
or gulp-read
.
API
read([options])
Reads the contents for each vinyl file from disk.
Options
buffer
: Whether or not the file contents should be aBuffer
. Setting this tofalse
will makefile.contents
a stream. (Default:true
)force
: Whether or not to reread file contents if they already exist. (Default:false
)stripBOM
: Whether or not to strip the BOM from file contents. (Default:true
)