webpack-shell-plugin icon indicating copy to clipboard operation
webpack-shell-plugin copied to clipboard

Does not wait for process to finish

Open rkaw92 opened this issue 8 years ago • 6 comments

We have a process that writes a value to a file which is then required by the actual build process like this:

git describe --tags HEAD >.app-version || date --rfc-3339=seconds >.app-version

Then, the "version file" generated as above is require()d in the application source.

It turns out this plugin does not wait for the command to finish before passing control back to webpack, because today we got an error during the JS build:

ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' ../.app-version in /builds/xxx/src

Here is a more minimal demonstration:

                new WebpackShellPlugin({
                        onBuildStart: [
                                'sleep 60; touch .myfile'
                        ],
                        safe: true
                })

Then, if you run your build as usual, it will actually finish before the file has been created. This prevents you from require()ing files generated as such in your webpack project.

I see 2 solutions:

  • Use the callback interface provided by Webpack plugin API, or
  • Use execSync instead of exec

rkaw92 avatar Feb 14 '17 11:02 rkaw92

Same issue here,plugin should wait for process to finish if possible. It's causing a compile loop for me because the pre-build process emits input for the actual webpack compilation after webpack has already completed its build process.

flyon avatar May 26 '17 11:05 flyon

Just made a pr https://github.com/1337programming/webpack-shell-plugin/pull/50

danielyaa5 avatar Aug 20 '17 21:08 danielyaa5

It would be great to get this merged - this is a pretty big blocker for using this lib for us.

charlieclark avatar Aug 24 '17 15:08 charlieclark

Is there any update on merging the PR? I can use npm pre- hook for now, but it doesn't execute when webpack rebuild the project on watch. This is a great plugin, it would be perfect for me if this feature is implemented. thanks!

Feiyang1 avatar Oct 27 '17 22:10 Feiyang1

Having the compile loop issue here too. would love to see this being merged!

arielsalminen avatar Oct 29 '17 17:10 arielsalminen

I made a fork that allows you to block until the scripts finish execution. please check it out: https://www.npmjs.com/package/webpack-synchronizable-shell-plugin

Feiyang1 avatar Nov 18 '17 22:11 Feiyang1