getChunkFiles.js 575 B

123456789101112131415161718
  1. const isRequired = require('./isRequired.js');
  2. /**
  3. * Finds all chunks of a webpack compilation object and maps the chunk name
  4. * to the first containing file.
  5. *
  6. * @param {Object} compilation - a webpack compilation object
  7. * @param {Object[]} compilation.chunks - an array of webpack chunks
  8. * @return {Object}
  9. */
  10. function getChunkFiles (compilation = isRequired('compilation')) {
  11. return compilation.chunks.reduce(function mapChunksToFiles(files, chunk) {
  12. files[chunk.name] = chunk.files;
  13. return files;
  14. }, {});
  15. }
  16. module.exports = getChunkFiles;