1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const util = require("util");
|
9 | const memoize = require("./util/memoize");
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const getJavascriptModulesPlugin = memoize(() =>
|
22 | require("./javascript/JavascriptModulesPlugin")
|
23 | );
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | class ModuleTemplate {
|
36 | |
37 |
|
38 |
|
39 |
|
40 | constructor(runtimeTemplate, compilation) {
|
41 | this._runtimeTemplate = runtimeTemplate;
|
42 | this.type = "javascript";
|
43 | this.hooks = Object.freeze({
|
44 | content: {
|
45 | tap: util.deprecate(
|
46 | (options, fn) => {
|
47 | getJavascriptModulesPlugin()
|
48 | .getCompilationHooks(compilation)
|
49 | .renderModuleContent.tap(
|
50 | options,
|
51 | (source, module, renderContext) =>
|
52 | fn(
|
53 | source,
|
54 | module,
|
55 | renderContext,
|
56 | renderContext.dependencyTemplates
|
57 | )
|
58 | );
|
59 | },
|
60 | "ModuleTemplate.hooks.content is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderModuleContent instead)",
|
61 | "DEP_MODULE_TEMPLATE_CONTENT"
|
62 | )
|
63 | },
|
64 | module: {
|
65 | tap: util.deprecate(
|
66 | (options, fn) => {
|
67 | getJavascriptModulesPlugin()
|
68 | .getCompilationHooks(compilation)
|
69 | .renderModuleContent.tap(
|
70 | options,
|
71 | (source, module, renderContext) =>
|
72 | fn(
|
73 | source,
|
74 | module,
|
75 | renderContext,
|
76 | renderContext.dependencyTemplates
|
77 | )
|
78 | );
|
79 | },
|
80 | "ModuleTemplate.hooks.module is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderModuleContent instead)",
|
81 | "DEP_MODULE_TEMPLATE_MODULE"
|
82 | )
|
83 | },
|
84 | render: {
|
85 | tap: util.deprecate(
|
86 | (options, fn) => {
|
87 | getJavascriptModulesPlugin()
|
88 | .getCompilationHooks(compilation)
|
89 | .renderModuleContainer.tap(
|
90 | options,
|
91 | (source, module, renderContext) =>
|
92 | fn(
|
93 | source,
|
94 | module,
|
95 | renderContext,
|
96 | renderContext.dependencyTemplates
|
97 | )
|
98 | );
|
99 | },
|
100 | "ModuleTemplate.hooks.render is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderModuleContainer instead)",
|
101 | "DEP_MODULE_TEMPLATE_RENDER"
|
102 | )
|
103 | },
|
104 | package: {
|
105 | tap: util.deprecate(
|
106 | (options, fn) => {
|
107 | getJavascriptModulesPlugin()
|
108 | .getCompilationHooks(compilation)
|
109 | .renderModulePackage.tap(
|
110 | options,
|
111 | (source, module, renderContext) =>
|
112 | fn(
|
113 | source,
|
114 | module,
|
115 | renderContext,
|
116 | renderContext.dependencyTemplates
|
117 | )
|
118 | );
|
119 | },
|
120 | "ModuleTemplate.hooks.package is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderModulePackage instead)",
|
121 | "DEP_MODULE_TEMPLATE_PACKAGE"
|
122 | )
|
123 | },
|
124 | hash: {
|
125 | tap: util.deprecate(
|
126 | (options, fn) => {
|
127 | compilation.hooks.fullHash.tap(options, fn);
|
128 | },
|
129 | "ModuleTemplate.hooks.hash is deprecated (use Compilation.hooks.fullHash instead)",
|
130 | "DEP_MODULE_TEMPLATE_HASH"
|
131 | )
|
132 | }
|
133 | });
|
134 | }
|
135 | }
|
136 |
|
137 | Object.defineProperty(ModuleTemplate.prototype, "runtimeTemplate", {
|
138 | get: util.deprecate(
|
139 | /**
|
140 | * @this {ModuleTemplate}
|
141 | * @returns {TODO} output options
|
142 | */
|
143 | function () {
|
144 | return this._runtimeTemplate;
|
145 | },
|
146 | "ModuleTemplate.runtimeTemplate is deprecated (use Compilation.runtimeTemplate instead)",
|
147 | "DEP_WEBPACK_CHUNK_TEMPLATE_OUTPUT_OPTIONS"
|
148 | )
|
149 | });
|
150 |
|
151 | module.exports = ModuleTemplate;
|