WebpackCompilerHandler.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. var __values = (this && this.__values) || function (o) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  4. if (m) return m.call(o);
  5. return {
  6. next: function () {
  7. if (o && i >= o.length) o = void 0;
  8. return { value: o && o[i++], done: !o };
  9. }
  10. };
  11. };
  12. Object.defineProperty(exports, "__esModule", { value: true });
  13. var WebpackCompilerHandler = /** @class */ (function () {
  14. function WebpackCompilerHandler(chunkIncludeTester, chunkHandler, assetManager, moduleCache, addBanner, perChunkOutput, additionalChunkModules, additionalModules) {
  15. this.chunkIncludeTester = chunkIncludeTester;
  16. this.chunkHandler = chunkHandler;
  17. this.assetManager = assetManager;
  18. this.moduleCache = moduleCache;
  19. this.addBanner = addBanner;
  20. this.perChunkOutput = perChunkOutput;
  21. this.additionalChunkModules = additionalChunkModules;
  22. this.additionalModules = additionalModules;
  23. }
  24. WebpackCompilerHandler.prototype.handleCompiler = function (compiler) {
  25. var _this = this;
  26. if (typeof compiler.hooks !== 'undefined') {
  27. compiler.hooks.compilation.tap('LicenseWebpackPlugin', function (compilation) {
  28. compilation.hooks.optimizeChunkAssets.tap('LicenseWebpackPlugin', function (chunks) {
  29. _this.iterateChunks(compilation, chunks);
  30. });
  31. });
  32. }
  33. else if (typeof compiler.plugin !== 'undefined') {
  34. compiler.plugin('compilation', function (compilation) {
  35. if (typeof compilation.plugin !== 'undefined') {
  36. compilation.plugin('optimize-chunk-assets', function (chunks, callback) {
  37. _this.iterateChunks(compilation, chunks);
  38. callback();
  39. });
  40. }
  41. });
  42. }
  43. };
  44. WebpackCompilerHandler.prototype.iterateChunks = function (compilation, chunks) {
  45. var _this = this;
  46. var _loop_1 = function (chunk) {
  47. if (this_1.chunkIncludeTester.isIncluded(chunk.name)) {
  48. this_1.chunkHandler.processChunk(compilation, chunk, this_1.moduleCache);
  49. if (this_1.additionalChunkModules[chunk.name]) {
  50. this_1.additionalChunkModules[chunk.name].forEach(function (module) {
  51. return _this.chunkHandler.processModule(compilation, chunk, _this.moduleCache, module);
  52. });
  53. }
  54. if (this_1.additionalModules.length > 0) {
  55. this_1.additionalModules.forEach(function (module) {
  56. return _this.chunkHandler.processModule(compilation, chunk, _this.moduleCache, module);
  57. });
  58. }
  59. if (this_1.perChunkOutput) {
  60. this_1.assetManager.writeChunkLicenses(this_1.moduleCache.getAllModulesForChunk(chunk.name), compilation, chunk);
  61. }
  62. if (this_1.addBanner) {
  63. this_1.assetManager.writeChunkBanners(this_1.moduleCache.getAllModulesForChunk(chunk.name), compilation, chunk);
  64. }
  65. }
  66. };
  67. var this_1 = this;
  68. try {
  69. for (var chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next(); !chunks_1_1.done; chunks_1_1 = chunks_1.next()) {
  70. var chunk = chunks_1_1.value;
  71. _loop_1(chunk);
  72. }
  73. }
  74. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  75. finally {
  76. try {
  77. if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1.return)) _a.call(chunks_1);
  78. }
  79. finally { if (e_1) throw e_1.error; }
  80. }
  81. if (!this.perChunkOutput) {
  82. this.assetManager.writeAllLicenses(this.moduleCache.getAllModules(), compilation);
  83. }
  84. var e_1, _a;
  85. };
  86. return WebpackCompilerHandler;
  87. }());
  88. exports.WebpackCompilerHandler = WebpackCompilerHandler;