I think there has been a false assumption in webpack-flush-chunks - that there is at least one chunk with the same name as the chunk group corresponding to the entry point or async chunk (provided via the before and after parameters and the chunkNames parameter respectively.
In an app I was working with this was not the case. The flushing of chunks was failing with the error "... check usage of babel plugin" because hasChunk was checking for a chunk with the required name, when it should instead be checking for a chunk group with the required name.
So the changes:
Rename functions to more accurately refer to the webpack concepts of chunks, chunk groups, entry points, and assets/files
Update hasChunk (now hasChunkGroup) to check the namedChunkGroups key in the stats object instead of the assetsByChunkName key, fixing the bug I experienced.
Remove the adding of a hyphen to the chunk name, which I assume is a workaround for the same issue
Update unit tests to add examples where:
The chunk name is different from the chunk group/entry point/split point name
A chunk group has multiple chunks, none of which have the same name as the chunk group
Webpack 4 introduced the concept of chunk groups.
I think there has been a false assumption in
webpack-flush-chunks
- that there is at least one chunk with the same name as the chunk group corresponding to the entry point or async chunk (provided via thebefore
andafter
parameters and thechunkNames
parameter respectively.In an app I was working with this was not the case. The flushing of chunks was failing with the error "... check usage of babel plugin" because
hasChunk
was checking for a chunk with the required name, when it should instead be checking for a chunk group with the required name.So the changes:
hasChunk
(nowhasChunkGroup
) to check thenamedChunkGroups
key in the stats object instead of theassetsByChunkName
key, fixing the bug I experienced.