source: trip-planner-front/node_modules/webpack/lib/web/JsonpChunkLoadingPlugin.js@ ceaed42

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

initial commit

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