1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/svg-sprite-loader/lib/utils/get-module-chunk.js

34 lines
904 B
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
/**
* Find nearest module chunk (not sure that is reliable method, but who cares).
* @see http://stackoverflow.com/questions/43202761/how-to-determine-all-module-chunks-in-webpack
* @param {NormalModule} module
* @param {NormalModule[]} modules - webpack 1 compat
* @return {Chunk|null}
*/
function getModuleChunk(module, modules) {
let chunks;
2024-01-16 21:26:16 +08:00
if (module.chunksIterable) {
2023-12-18 13:12:25 +08:00
chunks = Array.from(module.chunksIterable);
2024-01-16 21:26:16 +08:00
} else if (module.mapChunks) {
2023-12-18 13:12:25 +08:00
chunks = module.mapChunks();
} else {
chunks = module.chunks;
}
// webpack 1 compat
const issuer = typeof module.issuer === 'string'
? modules.find(m => m.request === module.issuer)
: module.issuer;
if (Array.isArray(chunks) && chunks.length > 0) {
return chunks[chunks.length - 1];
} else if (issuer) {
return getModuleChunk(issuer, modules);
}
return null;
}
module.exports = getModuleChunk;