In webpack4:
splitChunks: {
cacheGroups: {
a: {
test: (module, chunks)=>{
chunks.every(( chunk ) => { chunk.name === 'xxx' })
}
}
},
}
In webpack 5:
splitChunks: {
cacheGroups: {
a: {
test: (module, {moduleGraph, chunkGraph})=>{
// how to use chunkGraph?
// Which is the equivalent of `chunks.eveny(chunk => chunk.name === 'xxx')`
}
}
},
}
How to use ChunkGraph API? I try to use in this way,
return chunkGraph.getChunkModules(module).every((chunk) => {
return new RegExp(`^${root}\\/`).test(chunk.name);
});
But chunkGraph.getChunkModules(module).length === 0
is true.
I got this link
The correct
chunkGraph
method name isgetModuleChunks
:The method source-code is available in the link you provided: https://github.com/webpack/webpack/blob/a16909c5fd/lib/ChunkGraph.js#L474