-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stance on plugins that replace gulp.src? #744
Comments
I could also use a clear definition about the fundamental difference between a gulp plugin vs. a gulpfriendly module. What is it that draws the line between them? I'll take a stab at it here. Please correct me if I'm wrong. A gulp plugin
A gulp-friendly module
|
Something that provides a src/dest/watch is a vinyl adapter not a plugin. See https://medium.com/@contrahacks/gulp-3828e8126466 for more info. Examples of vinyl adapters are vinyl-fs, vinyl-ftp (if that ever came out) |
Thanks @contra. In that post you say that "a Vinyl adapter simply exposes a For example, a "fake vinyl file" stream created from an object in memory: var gulp = require('gulp');
var rev = require('gulp-rev');
var size = require('gulp-size');
var stream = require('stream');
var File = require('vinyl');
function fakeFile(file) {
var src = new stream.Readable({ objectMode: true });
src._read = function() {
this.push(new File(file));
this.push(null);
};
return src;
};
gulp.task("default", function() {
return fakeFile({ path: 'fake.json', contents: new Buffer(JSON.stringify({ a: 'b' })) })
.pipe(rev())
.pipe(size())
.pipe(gulp.dest('dist'));
}); What do you call this? (other than weird 😛) Basically, I'm currently encountering a situation where my gulpfile needs to programmatically generate a particular file. I can't |
What about the recipe Make stream from buffer (memory contents)? In the write-versions task it is shown how to create a new stream, push content into it and then use it like a gulp.src |
@lukehorvat Either way - if you replace src/dest/watch you are a vinyl adapter not a plugin. Being the head or tail of a stream = vinyl adapter. Simple as that. |
Have you coined an npm tag (like vinylplugin or similar) for these vinyl adapters? |
@robrich No npm tag for them yet, I think vinyladapter would probably make sense |
|
I believe Browserify is a good example of this (although it is a little more than a simple |
And, given the definition that gulp plugins accept vinyl file objects, those hypothetical plugins are most definitely "gulp-friendly". Maybe the term "gulp-friendly" should be a little more clear cut here, and should include these source streams. |
@IMPinball Browserify doesn't return vinyl files so it is not "gulp-friendly" |
Oh. Didn't know that. (They do a pretty good job of masking that, IMO.) |
In Writing a plugin, it states that a plugin "takes in Vinyl file objects" as input. What about a plugin that can create the vinyl stream itself, effectively replacing
gulp.src
?For example, a hypothetical plugin that generates a JS vinyl file on-the-fly from an object literal:
Is this kind of thing considered an acceptable way of writing a gulp plugin (i.e. won't get it blacklisted), or does it simply make for a "gulpfriendly" tool? Is it only acceptable if the plugin also allows itself to be used in the middle of a pipeline like a "regular" gulp plugin?
I suppose the docs could probably be clearer on this point.
The text was updated successfully, but these errors were encountered: