source: trip-planner-front/node_modules/webpack/lib/webworker/ImportScriptsChunkLoadingPlugin.js@ fa375fe

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

initial commit

  • 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 CreateScriptUrlRuntimeModule = require("../runtime/CreateScriptUrlRuntimeModule");
10const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
11const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
12
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 const isEnabledForChunk = chunk => {
31 const options = chunk.getEntryOptions();
32 const chunkLoading =
33 options && options.chunkLoading !== undefined
34 ? options.chunkLoading
35 : globalChunkLoading;
36 return chunkLoading === "import-scripts";
37 };
38 const onceForChunkSet = new WeakSet();
39 const handler = (chunk, set) => {
40 if (onceForChunkSet.has(chunk)) return;
41 onceForChunkSet.add(chunk);
42 if (!isEnabledForChunk(chunk)) return;
43 const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
44 set.add(RuntimeGlobals.moduleFactoriesAddOnly);
45 set.add(RuntimeGlobals.hasOwnProperty);
46 if (withCreateScriptUrl) set.add(RuntimeGlobals.createScriptUrl);
47 compilation.addRuntimeModule(
48 chunk,
49 new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl)
50 );
51 };
52 compilation.hooks.runtimeRequirementInTree
53 .for(RuntimeGlobals.ensureChunkHandlers)
54 .tap("ImportScriptsChunkLoadingPlugin", handler);
55 compilation.hooks.runtimeRequirementInTree
56 .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
57 .tap("ImportScriptsChunkLoadingPlugin", handler);
58 compilation.hooks.runtimeRequirementInTree
59 .for(RuntimeGlobals.hmrDownloadManifest)
60 .tap("ImportScriptsChunkLoadingPlugin", handler);
61 compilation.hooks.runtimeRequirementInTree
62 .for(RuntimeGlobals.baseURI)
63 .tap("ImportScriptsChunkLoadingPlugin", handler);
64 compilation.hooks.runtimeRequirementInTree
65 .for(RuntimeGlobals.createScriptUrl)
66 .tap("RuntimePlugin", (chunk, set) => {
67 compilation.addRuntimeModule(
68 chunk,
69 new CreateScriptUrlRuntimeModule()
70 );
71 return true;
72 });
73
74 compilation.hooks.runtimeRequirementInTree
75 .for(RuntimeGlobals.ensureChunkHandlers)
76 .tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => {
77 if (!isEnabledForChunk(chunk)) return;
78 set.add(RuntimeGlobals.publicPath);
79 set.add(RuntimeGlobals.getChunkScriptFilename);
80 });
81 compilation.hooks.runtimeRequirementInTree
82 .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
83 .tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => {
84 if (!isEnabledForChunk(chunk)) return;
85 set.add(RuntimeGlobals.publicPath);
86 set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
87 set.add(RuntimeGlobals.moduleCache);
88 set.add(RuntimeGlobals.hmrModuleData);
89 set.add(RuntimeGlobals.moduleFactoriesAddOnly);
90 });
91 compilation.hooks.runtimeRequirementInTree
92 .for(RuntimeGlobals.hmrDownloadManifest)
93 .tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => {
94 if (!isEnabledForChunk(chunk)) return;
95 set.add(RuntimeGlobals.publicPath);
96 set.add(RuntimeGlobals.getUpdateManifestFilename);
97 });
98 }
99 );
100 }
101}
102module.exports = ImportScriptsChunkLoadingPlugin;
Note: See TracBrowser for help on using the repository browser.