Skip to content

Instantly share code, notes, and snippets.

@yocontra
Last active August 29, 2015 13:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yocontra/10444687 to your computer and use it in GitHub Desktop.
Save yocontra/10444687 to your computer and use it in GitHub Desktop.
var util = require('loader-utils');
var File = require('vinyl');
var gulp2webpack = function(streamConstructor, opt) {
opt = opt || {};
return function(content) {
var cb = this.async();
if (opt.cacheable) this.cacheable();
var file = new File({
path: this.resourcePath,
base: this.context,
content: content
});
var stream = streamConstructor(util.parseQuery(this.query));
stream.once('error', this.emitError);
stream.once('data', function(file){
cb(null, file.content);
});
stream.write(file);
stream.end();
};
};
/*
Example usage:
*/
var react = require('gulp-react');
var loader = gulp2webpack(react, {cacheable: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment