source: trip-planner-front/node_modules/webpack/lib/prefetch/ChunkPrefetchPreloadPlugin.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const RuntimeGlobals = require("../RuntimeGlobals");
9const ChunkPrefetchFunctionRuntimeModule = require("./ChunkPrefetchFunctionRuntimeModule");
10const ChunkPrefetchStartupRuntimeModule = require("./ChunkPrefetchStartupRuntimeModule");
11const ChunkPrefetchTriggerRuntimeModule = require("./ChunkPrefetchTriggerRuntimeModule");
12const ChunkPreloadTriggerRuntimeModule = require("./ChunkPreloadTriggerRuntimeModule");
13
14/** @typedef {import("../Compiler")} Compiler */
15
16class ChunkPrefetchPreloadPlugin {
17 /**
18 * @param {Compiler} compiler the compiler
19 * @returns {void}
20 */
21 apply(compiler) {
22 compiler.hooks.compilation.tap(
23 "ChunkPrefetchPreloadPlugin",
24 compilation => {
25 compilation.hooks.additionalChunkRuntimeRequirements.tap(
26 "ChunkPrefetchPreloadPlugin",
27 (chunk, set, { chunkGraph }) => {
28 if (chunkGraph.getNumberOfEntryModules(chunk) === 0) return;
29 const startupChildChunks = chunk.getChildrenOfTypeInOrder(
30 chunkGraph,
31 "prefetchOrder"
32 );
33 if (startupChildChunks) {
34 set.add(RuntimeGlobals.prefetchChunk);
35 set.add(RuntimeGlobals.onChunksLoaded);
36 compilation.addRuntimeModule(
37 chunk,
38 new ChunkPrefetchStartupRuntimeModule(startupChildChunks)
39 );
40 }
41 }
42 );
43 compilation.hooks.additionalTreeRuntimeRequirements.tap(
44 "ChunkPrefetchPreloadPlugin",
45 (chunk, set, { chunkGraph }) => {
46 const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph, false);
47
48 if (chunkMap.prefetch) {
49 set.add(RuntimeGlobals.prefetchChunk);
50 compilation.addRuntimeModule(
51 chunk,
52 new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch)
53 );
54 }
55 if (chunkMap.preload) {
56 set.add(RuntimeGlobals.preloadChunk);
57 compilation.addRuntimeModule(
58 chunk,
59 new ChunkPreloadTriggerRuntimeModule(chunkMap.preload)
60 );
61 }
62 }
63 );
64 compilation.hooks.runtimeRequirementInTree
65 .for(RuntimeGlobals.prefetchChunk)
66 .tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
67 compilation.addRuntimeModule(
68 chunk,
69 new ChunkPrefetchFunctionRuntimeModule(
70 "prefetch",
71 RuntimeGlobals.prefetchChunk,
72 RuntimeGlobals.prefetchChunkHandlers
73 )
74 );
75 set.add(RuntimeGlobals.prefetchChunkHandlers);
76 });
77 compilation.hooks.runtimeRequirementInTree
78 .for(RuntimeGlobals.preloadChunk)
79 .tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
80 compilation.addRuntimeModule(
81 chunk,
82 new ChunkPrefetchFunctionRuntimeModule(
83 "preload",
84 RuntimeGlobals.preloadChunk,
85 RuntimeGlobals.preloadChunkHandlers
86 )
87 );
88 set.add(RuntimeGlobals.preloadChunkHandlers);
89 });
90 }
91 );
92 }
93}
94
95module.exports = ChunkPrefetchPreloadPlugin;
Note: See TracBrowser for help on using the repository browser.