execa-webpack-plugin
Version:
A better `child_process` for `webpack`
153 lines (126 loc) • 4.05 kB
Markdown
[](https://www.npmjs.org/package/execa-webpack-plugin)
[](https://travis-ci.org/itgalaxy/execa-webpack-plugin)
[](https://david-dm.org/itgalaxy/execa-webpack-plugin)
[](https://david-dm.org/itgalaxy/execa-webpack-plugin?type=dev)
[](https://greenkeeper.io)
A better `child_process` for `webpack`.
```shell
npm i -D execa-webpack-plugin
```
**webpack.config.js**
```js
const ExecaPlugin = require("execa-webpack-plugin");
module.exports = {
plugins: [
new ExecaPlugin({
onBeforeRun: [
{
args: ["build"],
cmd: "del",
options: {
cwd: process.cwd()
}
}
]
})
]
};
```
Note: [list of command options](https://github.com/sindresorhus/execa#options).
| Name | Type | Default | Description |
| :-------------------: | :---------: | :---------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| **`on(NameOfEvent)`** | `{Array}` | `[]` | Array of scripts to execute on the event. | |
| **`bail`** | `{Boolean}` | `compiler.options.bail` | Report the first error as a hard error instead of tolerating it. |
| **`dev`** | `{Boolean}` | `true` | Switch for development environments. This causes scripts to execute once. Useful for running HMR on webpack-dev-server or webpack watch mode. |
| **`logLevel`** | `string` | `warn` | Enable logging. |
List of [events](https://webpack.js.org/api/compiler-hooks/).
Name of event contain - `on` + event name (first character in upper case).
Examples: `onBeforeRun`, `onRun`, `onWatchRun`, `onCompile` and etc.
```js
[
new ExecaPlugin({
onBeforeRun: [
{
args: ["build"],
cmd: "del"
}
],
onCompile: [
{
args: ["check"],
cmd: "command"
}
],
// Support nested command
onDone: [
{
args: [
{
args: ["arg"],
cmd: "command-return-argument"
},
"other-argument",
{
args: ["arg"],
cmd: "command-return-other-argument"
}
],
cmd: "command"
}
]
})
];
```
```js
[
new ExecaPlugin({
bail: true,
onBeforeRun: [
{
args: ["build"],
cmd: "del"
}
]
})
];
```
If you want to run command(s) in `watch` mode every time you can set `dev` option to false.
```js
[
new ExecaPlugin({
dev: false,
onBeforeRun: [
{
args: ["build"],
cmd: "del"
}
]
})
];
```
Supports log [levels](https://github.com/webpack-contrib/webpack-log#level).
```js
[
new ExecaPlugin({
logLevel: "info",
onBeforeRun: [
{
args: ["build"],
cmd: "del"
}
]
})
];
```
* [execa](https://github.com/sindresorhus/execa) - API.