source: trip-planner-front/node_modules/webpack/lib/esm/ModuleChunkLoadingPlugin.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 2.5 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 ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
10const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
11
12/** @typedef {import("../Compiler")} Compiler */
13
14class ModuleChunkLoadingPlugin {
15 /**
16 * Apply the plugin
17 * @param {Compiler} compiler the compiler instance
18 * @returns {void}
19 */
20 apply(compiler) {
21 compiler.hooks.thisCompilation.tap(
22 "ModuleChunkLoadingPlugin",
23 compilation => {
24 const globalChunkLoading = compilation.outputOptions.chunkLoading;
25 const isEnabledForChunk = chunk => {
26 const options = chunk.getEntryOptions();
27 const chunkLoading =
28 (options && options.chunkLoading) || globalChunkLoading;
29 return chunkLoading === "import";
30 };
31 const onceForChunkSet = new WeakSet();
32 const handler = (chunk, set) => {
33 if (onceForChunkSet.has(chunk)) return;
34 onceForChunkSet.add(chunk);
35 if (!isEnabledForChunk(chunk)) return;
36 set.add(RuntimeGlobals.moduleFactoriesAddOnly);
37 set.add(RuntimeGlobals.hasOwnProperty);
38 compilation.addRuntimeModule(
39 chunk,
40 new ModuleChunkLoadingRuntimeModule(set)
41 );
42 };
43 compilation.hooks.runtimeRequirementInTree
44 .for(RuntimeGlobals.ensureChunkHandlers)
45 .tap("ModuleChunkLoadingPlugin", handler);
46 compilation.hooks.runtimeRequirementInTree
47 .for(RuntimeGlobals.baseURI)
48 .tap("ModuleChunkLoadingPlugin", handler);
49 compilation.hooks.runtimeRequirementInTree
50 .for(RuntimeGlobals.externalInstallChunk)
51 .tap("ModuleChunkLoadingPlugin", handler);
52 compilation.hooks.runtimeRequirementInTree
53 .for(RuntimeGlobals.onChunksLoaded)
54 .tap("ModuleChunkLoadingPlugin", handler);
55 compilation.hooks.runtimeRequirementInTree
56 .for(RuntimeGlobals.externalInstallChunk)
57 .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
58 if (!isEnabledForChunk(chunk)) return;
59 compilation.addRuntimeModule(
60 chunk,
61 new ExportWebpackRequireRuntimeModule()
62 );
63 });
64
65 compilation.hooks.runtimeRequirementInTree
66 .for(RuntimeGlobals.ensureChunkHandlers)
67 .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
68 if (!isEnabledForChunk(chunk)) return;
69 set.add(RuntimeGlobals.getChunkScriptFilename);
70 });
71 }
72 );
73 }
74}
75
76module.exports = ModuleChunkLoadingPlugin;
Note: See TracBrowser for help on using the repository browser.