A better child_process for webpack.
npm i -D execa-webpack-pluginwebpack.config.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.
List of hooks.
The name of hook contains: on + hook name (first character in upper case).
Examples: onBeforeRun, onRun, onWatchRun, onCompile and etc.
webpack.config.js
module.exports = {
plugins: [
[
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"
}
]
})
]
]
};Fail out on the first error instead of tolerating it. To enable it:
webpack.config.js
module.exports = {
plugins: [
[
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.
webpack.config.js
module.exports = {
plugins: [
new ExecaPlugin({
dev: false,
onBeforeRun: [
{
args: ["build"],
cmd: "del"
}
]
})
]
};webpack.config.js
module.exports = {
infrastructureLogging: {
level: "warn"
},
plugins: [
new ExecaPlugin({
onBeforeRun: [
{
args: ["build"],
cmd: "del"
}
]
})
]
};- execa - API.
