Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
Use webpack hooks
Browse files Browse the repository at this point in the history
In webpack 4, `Tapable#apply` and `Tapable#plugin` raise a **deprecation notice**.

- `Tapable#apply(plugin)` must be replaced by a call to `plugin.apply`
- `Tapable#plugin(hook, fn)` must be replaced by a call to `hook.tap` (or `hook.tapAsync`)

**Note:** This is breaking change because it drops webpack < 4 compatibility.
  • Loading branch information
ooflorent committed Mar 16, 2018
1 parent 8a676ec commit 98baeb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/friendly-errors-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FriendlyErrorsWebpackPlugin {

apply(compiler) {

compiler.plugin('done', stats => {
const doneFn = stats => {
this.clearConsole();

const hasErrors = stats.hasErrors();
Expand All @@ -55,12 +55,22 @@ class FriendlyErrorsWebpackPlugin {
if (hasWarnings) {
this.displayErrors(extractErrorsFromStats(stats, 'warnings'), 'warning');
}
});
};

compiler.plugin('invalid', () => {
const invalidFn = () => {
this.clearConsole();
output.title('info', 'WAIT', 'Compiling...');
});
};

if (compiler.hooks) {
const plugin = { name: 'FriendlyErrorsWebpackPlugin' };

compiler.hooks.done.tap(plugin, doneFn);
compiler.hooks.invalid.tap(plugin, invalidFn);
} else {
compiler.plugin('done', doneFn);
compiler.plugin('invalid', invalidFn);
}
}

clearConsole() {
Expand Down
2 changes: 1 addition & 1 deletion test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const webpackPromise = function (config, globalPlugins) {
const compiler = webpack(config);
compiler.outputFileSystem = new MemoryFileSystem();
if (Array.isArray(globalPlugins)) {
globalPlugins.forEach(p => compiler.apply(p));
globalPlugins.forEach(p => p.apply(compiler));
}

return new Promise((resolve, reject) => {
Expand Down

0 comments on commit 98baeb9

Please sign in to comment.