Skip to content
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

Expose original 'done' callback to the custom callback. #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 30 additions & 26 deletions index.js
Expand Up @@ -25,34 +25,38 @@ var defaultStatsOptions = {

module.exports = function(options, wp, done) {
options = options || {};
if (typeof done !== 'function') {
var callingDone = false;
done = function(err, stats) {
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 callingDone = false;
var webpackDone = function(err, stats) {
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));
}
};
if (typeof done === 'function') {
done = done.bind({ 'webpackDone': webpackDone });
} else {
done = webpackDone;
}

var webpack = wp || require('webpack');
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Expand Up @@ -54,7 +54,9 @@ gulp.task('default', function() {
});
```

Pass in 3rd argument if you want to access the stats outputted from webpack when the compilation is done:
Pass in 3rd argument if you want to access the stats outputted from webpack when the compilation is done.
In addition, if you wish to delegate to the original done callback, you may do it via call to
`this.webpackDone`:


```js
Expand All @@ -66,6 +68,9 @@ gulp.task('default', function() {
/* config */
}, null, function(err, stats) {
/* Use stats to do more things if needed */

/* Call original callback if needed */
this.webpackDone(err, stats);
}))
.pipe(gulp.dest('dist/'));
});
Expand Down