onBuildStart scripts being executed twice... on some cases
Closed this issue · 1 comments
We have our configuration divided among some files:
webpack.common.js
(main config file)webpack.dev.js
(config file for local development)webpack.prod.js
(config file for production build)webpack.tdd.js
(config file for TDD during local development)webpack.test.js
(config file fornpm test
)
In webpack.common.js
we have defined the following using webpack-shell-plugin-next
:
const WebpackShellPlugin = require('webpack-shell-plugin-next');
...
module.exports = {
...
plugins: [
...
new WebpackShellPlugin({
onBuildStart: {
scripts: [
`echo "${header}"`,
'echo "Building ..."'
]
},
onBuildEnd: {
scripts: [
'echo "Done!"'
]
},
...
}),
]
}
That header
variable contains a header for the console. The weird thing is that when we run npm start
, which starts a local server with webpack serve
, we get the header twice:
But when we run npm test
, the header appears only once:
The weirdest part is that the config file for development doesn't have any other WebpackShellPlugin
, but the one for test does. This is the second plugin for webpack.test.js
:
new WebpackShellPlugin({
onBuildStart: {
scripts: [
'echo "Removing coverage folders"',
'rm -rf coverage .nyc_output'
],
},
}),
So, when we run npm start
, with only one WebpackShellPlugin
, we get the header twice. And when we run npm test
, with two plugins that define, in total, two onBuildStart
and one onBuildEnd
, we get only one header. And both onBuildStart run exactly once, as expected.