source: imaps-frontend/node_modules/webpack/lib/ChunkTemplate.js

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 5.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 util = require("util");
9const memoize = require("./util/memoize");
10
11/** @typedef {import("tapable").Tap} Tap */
12/** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
13/** @typedef {import("./Chunk")} Chunk */
14/** @typedef {import("./Compilation")} Compilation */
15/** @typedef {import("./Compilation").ChunkHashContext} ChunkHashContext */
16/** @typedef {import("./Compilation").Hash} Hash */
17/** @typedef {import("./Compilation").RenderManifestEntry} RenderManifestEntry */
18/** @typedef {import("./Compilation").RenderManifestOptions} RenderManifestOptions */
19/** @typedef {import("./Compilation").Source} Source */
20/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
21/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
22/**
23 * @template T
24 * @typedef {import("tapable").IfSet<T>} IfSet
25 */
26
27const getJavascriptModulesPlugin = memoize(() =>
28 require("./javascript/JavascriptModulesPlugin")
29);
30
31// TODO webpack 6 remove this class
32class ChunkTemplate {
33 /**
34 * @param {OutputOptions} outputOptions output options
35 * @param {Compilation} compilation the compilation
36 */
37 constructor(outputOptions, compilation) {
38 this._outputOptions = outputOptions || {};
39 this.hooks = Object.freeze({
40 renderManifest: {
41 tap: util.deprecate(
42 /**
43 * @template AdditionalOptions
44 * @param {string | Tap & IfSet<AdditionalOptions>} options options
45 * @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn function
46 */
47 (options, fn) => {
48 compilation.hooks.renderManifest.tap(
49 options,
50 (entries, options) => {
51 if (options.chunk.hasRuntime()) return entries;
52 return fn(entries, options);
53 }
54 );
55 },
56 "ChunkTemplate.hooks.renderManifest is deprecated (use Compilation.hooks.renderManifest instead)",
57 "DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_MANIFEST"
58 )
59 },
60 modules: {
61 tap: util.deprecate(
62 /**
63 * @template AdditionalOptions
64 * @param {string | Tap & IfSet<AdditionalOptions>} options options
65 * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
66 */
67 (options, fn) => {
68 getJavascriptModulesPlugin()
69 .getCompilationHooks(compilation)
70 .renderChunk.tap(options, (source, renderContext) =>
71 fn(
72 source,
73 compilation.moduleTemplates.javascript,
74 renderContext
75 )
76 );
77 },
78 "ChunkTemplate.hooks.modules is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderChunk instead)",
79 "DEP_WEBPACK_CHUNK_TEMPLATE_MODULES"
80 )
81 },
82 render: {
83 tap: util.deprecate(
84 /**
85 * @template AdditionalOptions
86 * @param {string | Tap & IfSet<AdditionalOptions>} options options
87 * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
88 */
89 (options, fn) => {
90 getJavascriptModulesPlugin()
91 .getCompilationHooks(compilation)
92 .renderChunk.tap(options, (source, renderContext) =>
93 fn(
94 source,
95 compilation.moduleTemplates.javascript,
96 renderContext
97 )
98 );
99 },
100 "ChunkTemplate.hooks.render is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderChunk instead)",
101 "DEP_WEBPACK_CHUNK_TEMPLATE_RENDER"
102 )
103 },
104 renderWithEntry: {
105 tap: util.deprecate(
106 /**
107 * @template AdditionalOptions
108 * @param {string | Tap & IfSet<AdditionalOptions>} options options
109 * @param {function(Source, Chunk): Source} fn function
110 */
111 (options, fn) => {
112 getJavascriptModulesPlugin()
113 .getCompilationHooks(compilation)
114 .render.tap(options, (source, renderContext) => {
115 if (
116 renderContext.chunkGraph.getNumberOfEntryModules(
117 renderContext.chunk
118 ) === 0 ||
119 renderContext.chunk.hasRuntime()
120 ) {
121 return source;
122 }
123 return fn(source, renderContext.chunk);
124 });
125 },
126 "ChunkTemplate.hooks.renderWithEntry is deprecated (use JavascriptModulesPlugin.getCompilationHooks().render instead)",
127 "DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_WITH_ENTRY"
128 )
129 },
130 hash: {
131 tap: util.deprecate(
132 /**
133 * @template AdditionalOptions
134 * @param {string | Tap & IfSet<AdditionalOptions>} options options
135 * @param {function(Hash): void} fn function
136 */
137 (options, fn) => {
138 compilation.hooks.fullHash.tap(options, fn);
139 },
140 "ChunkTemplate.hooks.hash is deprecated (use Compilation.hooks.fullHash instead)",
141 "DEP_WEBPACK_CHUNK_TEMPLATE_HASH"
142 )
143 },
144 hashForChunk: {
145 tap: util.deprecate(
146 /**
147 * @template AdditionalOptions
148 * @param {string | Tap & IfSet<AdditionalOptions>} options options
149 * @param {function(Hash, Chunk, ChunkHashContext): void} fn function
150 */
151 (options, fn) => {
152 getJavascriptModulesPlugin()
153 .getCompilationHooks(compilation)
154 .chunkHash.tap(options, (chunk, hash, context) => {
155 if (chunk.hasRuntime()) return;
156 fn(hash, chunk, context);
157 });
158 },
159 "ChunkTemplate.hooks.hashForChunk is deprecated (use JavascriptModulesPlugin.getCompilationHooks().chunkHash instead)",
160 "DEP_WEBPACK_CHUNK_TEMPLATE_HASH_FOR_CHUNK"
161 )
162 }
163 });
164 }
165}
166
167Object.defineProperty(ChunkTemplate.prototype, "outputOptions", {
168 get: util.deprecate(
169 /**
170 * @this {ChunkTemplate}
171 * @returns {OutputOptions} output options
172 */
173 function () {
174 return this._outputOptions;
175 },
176 "ChunkTemplate.outputOptions is deprecated (use Compilation.outputOptions instead)",
177 "DEP_WEBPACK_CHUNK_TEMPLATE_OUTPUT_OPTIONS"
178 )
179});
180
181module.exports = ChunkTemplate;
Note: See TracBrowser for help on using the repository browser.