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

Fix for webpack 5 watch mode deprecation: DEP_WEBPACK_WATCH_WITHOUT_CALLBACK #232

Merged
merged 1 commit into from
Dec 6, 2020
Merged
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
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