serverless-plugin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. class ServerlessPlugin {
  6. apply(compiler) {
  7. compiler.hooks.compilation.tap("ServerlessPlugin", (compilation)=>{
  8. const hook = compilation.hooks.optimizeChunks;
  9. hook.tap("ServerlessPlugin", (chunks)=>{
  10. for (const chunk of chunks){
  11. // If chunk is not an entry point skip them
  12. // @ts-ignore TODO: Remove ignore when webpack 5 is stable
  13. if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0) {
  14. continue;
  15. }
  16. // Async chunks are usages of import() for example
  17. const dynamicChunks = chunk.getAllAsyncChunks();
  18. for (const dynamicChunk of dynamicChunks){
  19. // @ts-ignore TODO: Remove ignore when webpack 5 is stable
  20. for (const module of compilation.chunkGraph.getChunkModulesIterable(dynamicChunk)){
  21. // Add module back into the entry chunk
  22. // @ts-ignore TODO: Remove ignore when webpack 5 is stable
  23. if (!compilation.chunkGraph.isModuleInChunk(module, chunk)) {
  24. // @ts-ignore TODO: Remove ignore when webpack 5 is stable
  25. compilation.chunkGraph.connectChunkAndModule(chunk, module);
  26. }
  27. }
  28. }
  29. }
  30. });
  31. });
  32. }
  33. }
  34. exports.ServerlessPlugin = ServerlessPlugin;
  35. //# sourceMappingURL=serverless-plugin.js.map