source: imaps-frontend/node_modules/webpack/lib/prefetch/ChunkPrefetchPreloadPlugin.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.0 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("../Chunk")} Chunk */
15/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
16/** @typedef {import("../Compiler")} Compiler */
17
18class ChunkPrefetchPreloadPlugin {
19 /**
20 * @param {Compiler} compiler the compiler
21 * @returns {void}
22 */
23 apply(compiler) {
24 compiler.hooks.compilation.tap(
25 "ChunkPrefetchPreloadPlugin",
26 compilation => {
27 compilation.hooks.additionalChunkRuntimeRequirements.tap(
28 "ChunkPrefetchPreloadPlugin",
29 (chunk, set, { chunkGraph }) => {
30 if (chunkGraph.getNumberOfEntryModules(chunk) === 0) return;
31 const startupChildChunks = chunk.getChildrenOfTypeInOrder(
32 chunkGraph,
33 "prefetchOrder"
34 );
35 if (startupChildChunks) {
36 set.add(RuntimeGlobals.prefetchChunk);
37 set.add(RuntimeGlobals.onChunksLoaded);
38 set.add(RuntimeGlobals.exports);
39 compilation.addRuntimeModule(
40 chunk,
41 new ChunkPrefetchStartupRuntimeModule(startupChildChunks)
42 );
43 }
44 }
45 );
46 compilation.hooks.additionalTreeRuntimeRequirements.tap(
47 "ChunkPrefetchPreloadPlugin",
48 (chunk, set, { chunkGraph }) => {
49 const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph);
50
51 if (chunkMap.prefetch) {
52 set.add(RuntimeGlobals.prefetchChunk);
53 compilation.addRuntimeModule(
54 chunk,
55 new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch)
56 );
57 }
58 if (chunkMap.preload) {
59 set.add(RuntimeGlobals.preloadChunk);
60 compilation.addRuntimeModule(
61 chunk,
62 new ChunkPreloadTriggerRuntimeModule(chunkMap.preload)
63 );
64 }
65 }
66 );
67 compilation.hooks.runtimeRequirementInTree
68 .for(RuntimeGlobals.prefetchChunk)
69 .tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
70 compilation.addRuntimeModule(
71 chunk,
72 new ChunkPrefetchFunctionRuntimeModule(
73 "prefetch",
74 RuntimeGlobals.prefetchChunk,
75 RuntimeGlobals.prefetchChunkHandlers
76 )
77 );
78 set.add(RuntimeGlobals.prefetchChunkHandlers);
79 });
80 compilation.hooks.runtimeRequirementInTree
81 .for(RuntimeGlobals.preloadChunk)
82 .tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
83 compilation.addRuntimeModule(
84 chunk,
85 new ChunkPrefetchFunctionRuntimeModule(
86 "preload",
87 RuntimeGlobals.preloadChunk,
88 RuntimeGlobals.preloadChunkHandlers
89 )
90 );
91 set.add(RuntimeGlobals.preloadChunkHandlers);
92 });
93 }
94 );
95 }
96}
97
98module.exports = ChunkPrefetchPreloadPlugin;
Note: See TracBrowser for help on using the repository browser.