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
We have a process that writes a value to a file which is then required by the actual build process like this:
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:
Here is a more minimal demonstration:
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: