source: imaps-frontend/node_modules/webpack/lib/webworker/ImportScriptsChunkLoadingPlugin.js@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.7 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 StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
10const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
11
12/** @typedef {import("../Chunk")} Chunk */
13/** @typedef {import("../Compiler")} Compiler */
14
15class ImportScriptsChunkLoadingPlugin {
16 /**
17 * Apply the plugin
18 * @param {Compiler} compiler the compiler instance
19 * @returns {void}
20 */
21 apply(compiler) {
22 new StartupChunkDependenciesPlugin({
23 chunkLoading: "import-scripts",
24 asyncChunkLoading: true
25 }).apply(compiler);
26 compiler.hooks.thisCompilation.tap(
27 "ImportScriptsChunkLoadingPlugin",
28 compilation => {
29 const globalChunkLoading = compilation.outputOptions.chunkLoading;
30 /**
31 * @param {Chunk} chunk chunk
32 * @returns {boolean} true, if wasm loading is enabled for the chunk
33 */
34 const isEnabledForChunk = chunk => {
35 const options = chunk.getEntryOptions();
36 const chunkLoading =
37 options && options.chunkLoading !== undefined
38 ? options.chunkLoading
39 : globalChunkLoading;
40 return chunkLoading === "import-scripts";
41 };
42 const onceForChunkSet = new WeakSet();
43 /**
44 * @param {Chunk} chunk chunk
45 * @param {Set<string>} set runtime requirements
46 */
47 const handler = (chunk, set) => {
48 if (onceForChunkSet.has(chunk)) return;
49 onceForChunkSet.add(chunk);
50 if (!isEnabledForChunk(chunk)) return;
51 const withCreateScriptUrl = Boolean(
52 compilation.outputOptions.trustedTypes
53 );
54 set.add(RuntimeGlobals.moduleFactoriesAddOnly);
55 set.add(RuntimeGlobals.hasOwnProperty);
56 if (withCreateScriptUrl) {
57 set.add(RuntimeGlobals.createScriptUrl);
58 }
59 compilation.addRuntimeModule(
60 chunk,
61 new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl)
62 );
63 };
64 compilation.hooks.runtimeRequirementInTree
65 .for(RuntimeGlobals.ensureChunkHandlers)
66 .tap("ImportScriptsChunkLoadingPlugin", handler);
67 compilation.hooks.runtimeRequirementInTree
68 .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
69 .tap("ImportScriptsChunkLoadingPlugin", handler);
70 compilation.hooks.runtimeRequirementInTree
71 .for(RuntimeGlobals.hmrDownloadManifest)
72 .tap("ImportScriptsChunkLoadingPlugin", handler);
73 compilation.hooks.runtimeRequirementInTree
74 .for(RuntimeGlobals.baseURI)
75 .tap("ImportScriptsChunkLoadingPlugin", handler);
76
77 compilation.hooks.runtimeRequirementInTree
78 .for(RuntimeGlobals.ensureChunkHandlers)
79 .tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => {
80 if (!isEnabledForChunk(chunk)) return;
81 set.add(RuntimeGlobals.publicPath);
82 set.add(RuntimeGlobals.getChunkScriptFilename);
83 });
84 compilation.hooks.runtimeRequirementInTree
85 .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
86 .tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => {
87 if (!isEnabledForChunk(chunk)) return;
88 set.add(RuntimeGlobals.publicPath);
89 set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
90 set.add(RuntimeGlobals.moduleCache);
91 set.add(RuntimeGlobals.hmrModuleData);
92 set.add(RuntimeGlobals.moduleFactoriesAddOnly);
93 });
94 compilation.hooks.runtimeRequirementInTree
95 .for(RuntimeGlobals.hmrDownloadManifest)
96 .tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => {
97 if (!isEnabledForChunk(chunk)) return;
98 set.add(RuntimeGlobals.publicPath);
99 set.add(RuntimeGlobals.getUpdateManifestFilename);
100 });
101 }
102 );
103 }
104}
105module.exports = ImportScriptsChunkLoadingPlugin;
Note: See TracBrowser for help on using the repository browser.