Must call compiler.close() to write webpack filesystem cache #250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As per #246,
grunt-webpackhas been observed to not work with webpack 5 filesystem caching. This is a result of not calling (and waiting for)compiler.close(callback). Webpack defaults to waiting until idle to flush its cache to the filesystem, so this does not impact dev/watch mode, but withcompiler.run()you exit before hitting idle, and thus, never write the filesystem cache (bug!).Details of PR
This PR modifies a few more lines than might be expected because we have to handles change in async flow control. I tried to keep the diff very short and easy to compare to before for easy verification of same-behavior.
This is a standard webpack 5 migration issue that grunt-webpack still needs
The need to invoke

compiler.close()is specified in the webpack 5 migration guide:Additionally you can find a resolved issue on the webpack issue tracker containing the same advice to remedy the same problem: webpack/webpack#12342 (comment)
Verification of PR
This has been tested and fixes outputting webpack cache data to the filesystem in code.org's fairly large webpack config.
Using this PR combined with a webpack.config.js with
cache: { type: 'filesystem' }results in webpack cache being output to disk, whereas before this PR the build succeeds but no cache is written to disk.Fixes: #246