Skip to content

Commit

Permalink
- Corrected several syntaxical inconsistencies (quoting, single-state…
Browse files Browse the repository at this point in the history
…ment

  blocks, indentation, opt = opt || default idiom), no semantic impact
- Added .editorconfig
- Default value for stats in the 'done' callback (when webpack crashes
  before generating stats, eg. file error)
- More idiomatic PluginError (Error object err is passed instead of err.message)
  • Loading branch information
elierotenberg committed Dec 1, 2014
1 parent acb70c5 commit 094e933
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
@@ -0,0 +1,8 @@
root=true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
37 changes: 25 additions & 12 deletions index.js
Expand Up @@ -4,7 +4,7 @@ var gutil = require('gulp-util');
var File = require('vinyl');
var MemoryFileSystem = require('memory-fs');
var through = require('through');
var ProgressPlugin = require("webpack/lib/ProgressPlugin");
var ProgressPlugin = require('webpack/lib/ProgressPlugin');

var PLUGIN_NAME = 'gulp-webpack';

Expand All @@ -13,7 +13,10 @@ module.exports = function(options, wp, done) {
if (typeof done !== 'function') {
var callingDone = false;
done = function(err, stats) {
if (options.quiet || callingDone) return;
stats = stats || {};
if (options.quiet || callingDone) {
return;
}
// Debounce output a little for when in watch mode
if (options.watch) {
callingDone = true;
Expand Down Expand Up @@ -43,9 +46,13 @@ module.exports = function(options, wp, done) {
var entries = Object.create(null);

var stream = through(function(file) {
if (file.isNull()) return;
if (file.isNull()) {
return;
}
if ('named' in file) {
if (!Array.isArray(entries[file.named])) entries[file.named] = [];
if (!Array.isArray(entries[file.named])) {
entries[file.named] = [];
}
entries[file.named].push(file.path);
} else {
entry = entry || [];
Expand All @@ -66,9 +73,9 @@ module.exports = function(options, wp, done) {
entry = entry[0] || entry;
}

if (!options.entry) options.entry = entry;
if (!options.output.path) options.output.path = process.cwd();
if (!options.output.filename) options.output.filename = '[hash].js';
options.entry = options.entry || entry;
options.output.path = options.output.path || process.cwd();
options.output.filename = options.output.filename || '[hash].js';

if (!options.entry) {
gutil.log('gulp-webpack - No files given; aborting compilation');
Expand All @@ -77,18 +84,22 @@ module.exports = function(options, wp, done) {

var compiler = webpack(options, function(err, stats) {
if (err) {
self.emit('error', new gutil.PluginError(PLUGIN_NAME, err.message));
self.emit('error', new gutil.PluginError(PLUGIN_NAME, err));
}
if (!options.watch) {
self.queue(null);
}
if (!options.watch) self.queue(null);
done(err, stats);
if (options.watch && !options.quiet) {
gutil.log("Webpack is watching for changes");
gutil.log('Webpack is watching for changes');
}
});

// In watch mode webpack returns a wrapper object so we need to get
// the underlying compiler
if (options.watch) compiler = compiler.compiler;
if (options.watch) {
compiler = compiler.compiler;
}

if (options.progress) {
compiler.apply(new ProgressPlugin(function(percentage, msg) {
Expand Down Expand Up @@ -126,5 +137,7 @@ module.exports = function(options, wp, done) {

// Expose webpack if asked
Object.defineProperty(module.exports, 'webpack', {
get: function() { return require('webpack'); }
get: function() {
return require('webpack');
}
});

0 comments on commit 094e933

Please sign in to comment.