s00d / webpack-shell-plugin-next

Run shell commands either before or after webpack 4 and 5 builds
MIT License
92 stars 12 forks source link

onBuildStart scripts being executed twice... on some cases #32

Closed dhAlcojor closed 1 year ago

dhAlcojor commented 3 years ago

We have our configuration divided among some files:

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: image

But when we run npm test, the header appears only once: image

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.

s00d commented 3 years ago

image

Hello. It looks like a problem on your side, can you create a repository with an example?