|
5 | 5 | [](https://travis-ci.org/iamogbz/webpack-compiler-plugin) |
6 | 6 | [](https://coveralls.io/github/iamogbz/webpack-compiler-plugin?branch=master) |
7 | 7 |
|
8 | | -Easily listen to webpack compiler hooks and execute commands on events |
| 8 | +Easily listen to `webpack` compiler hooks and execute commands on events. |
9 | 9 |
|
10 | | -## Shell Commands |
| 10 | +## API |
11 | 11 |
|
12 | | -```sh |
13 | | -npm run test # run jest tests |
14 | | -``` |
| 12 | +This plugin runs your specified commands at keys stages in the `webpack` build process. |
15 | 13 |
|
16 | | -```sh |
17 | | -npm run commit # run commitizen |
18 | | -``` |
| 14 | +### `buildStart` |
19 | 15 |
|
20 | | -```sh |
21 | | -npm run build # webpack build |
22 | | -``` |
| 16 | +This is run only once when the `webpack` build is first started, just after plugin are loaded. |
23 | 17 |
|
24 | | -### Typescript |
| 18 | +See [webpack.compiler.hook.afterPlugins](https://webpack.js.org/api/compiler-hooks/#afterplugins). |
25 | 19 |
|
26 | | -```sh |
27 | | -make typescript |
28 | | -``` |
| 20 | +### `compileStart` |
| 21 | + |
| 22 | +This is run every time `webpack` starts compiling the source code, can be run multiple times when using the `--watch` flag. |
| 23 | + |
| 24 | +See [webpack.compiler.hook.compilation](https://webpack.js.org/api/compiler-hooks/#compilation). |
| 25 | + |
| 26 | +### `compileEnd` |
| 27 | + |
| 28 | +This is run every time `webpack` finishes compiling the source code, just after the code is emitted. |
29 | 29 |
|
30 | | -[Example conversion](https://github.com/iamogbz/node-js-boilerplate/compare/typescript-conversion) |
| 30 | +See [webpack.compiler.hook.done](https://webpack.js.org/api/compiler-hooks/#done). |
| 31 | + |
| 32 | +### `buildEnd` |
| 33 | + |
| 34 | +This is the last stage run only when the build process is exiting. Is also triggered when exiting is caused by a build failure, interrupt signal, etc. |
| 35 | + |
| 36 | +See [node.process.exit](https://nodejs.org/api/process.html#process_event_exit). |
| 37 | + |
| 38 | +## Example |
| 39 | + |
| 40 | +```js |
| 41 | +/* webpack.config.js */ |
| 42 | + |
| 43 | +const { execSync } = require("child_process"); |
| 44 | +const { WebpackCompilerPlugin } = require("webpack-compile-plugin"); |
| 45 | + |
| 46 | +module.exports = { |
| 47 | + mode: "development", |
| 48 | + plugins: [ |
| 49 | + new WebpackCompilerPlugin({ |
| 50 | + name: "my-compile-plugin", |
| 51 | + listeners: { |
| 52 | + buildStart: () => execSync("echo 'hello'"), |
| 53 | + buildEnd: () => execSync("echo 'bye bye'"), |
| 54 | + }, |
| 55 | + }), |
| 56 | + ], |
| 57 | +}; |
| 58 | +``` |
0 commit comments