How to use ChunkGraph API in webpack 5. splitchunks.cacheGroup?

Viewed 1030

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

1 Answers
Related