Skip to content

Commit

Permalink
docs: improve custom plugin hooks documentation (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-oles authored Aug 1, 2021
1 parent 4cb7e39 commit 7150ffa
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,24 +362,37 @@ When we call this method with a [webpack compiler instance](https://webpack.js.o
[tapable](https://github.com/webpack/tapable) hooks where you can pass in your callbacks.

```js
const webpack = require('webpack');
// ./src/webpack/MyWebpackPlugin.js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

const compiler = webpack({
// ... webpack config
});
class MyWebpackPlugin {
apply(compiler) {
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);

// log some message on waiting
hooks.waiting.tap('MyPlugin', () => {
console.log('waiting for issues');
});
// don't show warnings
hooks.issues.tap('MyPlugin', (issues) =>
issues.filter((issue) => issue.severity === 'error')
);
}
}

// optionally add the plugin to the compiler
// **don't do this if already added through configuration**
new ForkTsCheckerWebpackPlugin().apply(compiler);
module.exports = MyWebpackPlugin;

// now get the plugin hooks from compiler
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);
// webpack.config.js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const MyWebpackPlugin = require('./src/webpack/MyWebpackPlugin');

// say we want to show some message when plugin is waiting for issues results
hooks.waiting.tap('yourListenerName', () => {
console.log('waiting for issues');
});
module.exports = {
/* ... */
plugins: [
new ForkTsCheckerWebpackPlugin(),
new MyWebpackPlugin()
]
};
```

## Typings
Expand Down

0 comments on commit 7150ffa

Please sign in to comment.