Skip to content

Commit

Permalink
Merge pull request #232 from shama/webpack-watch
Browse files Browse the repository at this point in the history
Fix for webpack 5 watch mode deprecation: DEP_WEBPACK_WATCH_WITHOUT_CALLBACK
  • Loading branch information
shama committed Dec 6, 2020
2 parents 7e346b5 + 03a6a70 commit bbe9d9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = function (options, wp, done) {
options = clone(options) || {};
var config = options.config || options;

const isInWatchMode = !!options.watch;
delete options.watch;

// Webpack 4 doesn't support the `quiet` attribute, however supports
// setting `stats` to a string within an array of configurations
// (errors-only|minimal|none|normal|verbose) or an object with an absurd
Expand All @@ -54,7 +57,7 @@ module.exports = function (options, wp, done) {
}

// Debounce output a little for when in watch mode
if (options.watch) {
if (isInWatchMode) {
callingDone = true;
setTimeout(function () {
callingDone = false;
Expand Down Expand Up @@ -104,7 +107,6 @@ module.exports = function (options, wp, done) {
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) {
Expand All @@ -120,7 +122,6 @@ module.exports = function (options, wp, done) {
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) {
Expand Down Expand Up @@ -181,21 +182,21 @@ module.exports = function (options, wp, done) {

var errorMessage = errors.map(resolveErrorMessage).join('\n');
var compilationError = new PluginError('webpack-stream', errorMessage);
if (!options.watch) {
if (!isInWatchMode) {
self.emit('error', compilationError);
}
self.emit('compilation-error', compilationError);
}
if (!options.watch) {
if (!isInWatchMode) {
self.queue(null);
}
done(err, stats);
if (options.watch && !isSilent) {
if (isInWatchMode && !isSilent) {
fancyLog('webpack is watching for changes');
}
};

if (options.watch) {
if (isInWatchMode) {
const watchOptions = options.watchOptions || {};
compiler.watch(watchOptions, callback);
} else {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"node": ">= 8.0.0"
},
"scripts": {
"start": "gulp",
"debug": "node --inspect-brk ./node_modules/.bin/gulp",
"test": "semistandard && node test/test.js"
},
"files": [
Expand Down

0 comments on commit bbe9d9e

Please sign in to comment.