description and source-codewebpack-stream = function (options, wp, done) {
options = clone(options) || {};
var config = options.config || options;
if (typeof done !== 'function') {
var callingDone = false;
done = function (err, stats) {
if (err) {
// The err is here just to match the API but isnt used
return;
}
stats = stats || {};
if (options.quiet || callingDone) {
return;
}
// Debounce output a little for when in watch mode
if (options.watch) {
callingDone = true;
setTimeout(function () {
callingDone = false;
}, 500);
}
if (options.verbose) {
gutil.log(stats.toString({
colors: gutil.colors.supportsColor
}));
} else {
var statsOptions = options && options.stats || {};
Object.keys(defaultStatsOptions).forEach(function (key) {
if (typeof statsOptions[key] === 'undefined') {
statsOptions[key] = defaultStatsOptions[key];
}
});
gutil.log(stats.toString(statsOptions));
}
};
}
var webpack = wp || require('webpack');
var entry = [];
var entries = Object.create(null);
var stream = through(function (file) {
if (file.isNull()) {
return;
}
if ('named' in file) {
if (!Array.isArray(entries[file.named])) {
entries[file.named] = [];
}
entries[file.named].push(file.path);
} else {
entry = entry || [];
entry.push(file.path);
}
}, function () {
var self = this;
var handleConfig = function (config) {
config.output = config.output || {};
config.watch = !!options.watch;
// Determine pipe'd in entry
if (Object.keys(entries).length > 0) {
entry = entries;
if (!config.output.filename) {
// Better output default for multiple chunks
config.output.filename = '[name].js';
}
} else if (entry.length < 2) {
entry = entry[0] || entry;
}
config.entry = config.entry || entry;
config.output.path = config.output.path || process.cwd();
config.output.filename = config.output.filename || '[hash].js';
config.watch = options.watch;
entry = [];
if (!config.entry || config.entry.length < 1) {
gutil.log('webpack-stream - No files given; aborting compilation');
self.emit('end');
return false;
}
return true;
};
var succeeded;
if (Array.isArray(config)) {
for (var i = 0; i < config.length; i++) {
succeeded = handleConfig(config[i]);
if (!succeeded) {
return false;
}
}
} else {
succeeded = handleConfig(config);
if (!succeeded) {
return false;
}
}
var compiler = webpack(config, function (err, stats) {
if (err) {
self.emit('error', new gutil.PluginError('webpack-stream', err));
}
var jsonStats = stats.toJson() || {};
var errors = jsonStats.errors || [];
if (errors.length) {
var errorMessage = errors.reduce(function (resultMessage, nextError) {
resultMessage += nextError.toString();
return resultMessage;
}, '');
self.emit('error', new gutil.PluginError('webpack-stream', errorMessage));
}
if (!options.watch) {
self.queue(null);
}
done(err, stats);
if (options.watch && !options.quiet) {
gutil.log('webpack is watching for changes');
}
});
var handleCompiler = function (compiler) {
// In watch mode webpack returns a wrapper object so we need to get
// the underlying compiler
if (options.watch && compiler.compiler) {
compiler = compiler.compiler;
}
if (options.progress) {
compiler.apply(new ProgressPlugin(function (percentage, msg) {
percentage = Math.floor(percentage * 100);
msg = percentage + '% ' + msg;
if (percentage < 10) msg = ' ' + msg;
gutil.log('webpack', msg);
}));
}
var fs = compiler.outp ...