MCPcopy
hub / github.com/webpack/webpack / render

Method render

lib/library/AmdLibraryPlugin.js:89–162  ·  view source on GitHub ↗

* Returns source with library export. * @param {Source} source source * @param {RenderContext} renderContext render context * @param {LibraryContext<T>} libraryContext context * @returns {Source} source with library export

(
		source,
		{ chunkGraph, chunk, runtimeTemplate },
		{ options, compilation }
	)

Source from the content-addressed store, hash-verified

87 * @returns {Source} source with library export
88 */
89 render(
90 source,
91 { chunkGraph, chunk, runtimeTemplate },
92 { options, compilation }
93 ) {
94 const modern = runtimeTemplate.supportsArrowFunction();
95 const modules = chunkGraph
96 .getChunkModules(chunk)
97 .filter(
98 (m) =>
99 m instanceof ExternalModule &&
100 (m.externalType === "amd" || m.externalType === "amd-require")
101 );
102 const externals = /** @type {ExternalModule[]} */ (modules);
103 const externalsDepsArray = JSON.stringify(
104 externals.map((m) =>
105 typeof m.request === "object" && !Array.isArray(m.request)
106 ? m.request.amd
107 : m.request
108 )
109 );
110 const externalsArguments = externals
111 .map(
112 (m) =>
113 `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
114 `${chunkGraph.getModuleId(m)}`
115 )}__`
116 )
117 .join(", ");
118
119 const iife = runtimeTemplate.isIIFE();
120 const fnStart =
121 (modern
122 ? `(${externalsArguments}) => {`
123 : `function(${externalsArguments}) {`) +
124 (iife || !chunk.hasRuntime() ? " return " : "\n");
125 const fnEnd = iife ? ";\n}" : "\n}";
126
127 let amdContainerPrefix = "";
128 if (options.amdContainer) {
129 amdContainerPrefix = `${options.amdContainer}.`;
130 }
131
132 if (this.requireAsWrapper) {
133 return new ConcatSource(
134 `${amdContainerPrefix}require(${externalsDepsArray}, ${fnStart}`,
135 source,
136 `${fnEnd});`
137 );
138 } else if (options.name) {
139 const name = compilation.getPath(options.name, {
140 chunk
141 });
142
143 return new ConcatSource(
144 `${amdContainerPrefix}define(${JSON.stringify(
145 name
146 )}, ${externalsDepsArray}, ${fnStart}`,

Callers

nothing calls this directly

Calls 8

supportsArrowFunctionMethod · 0.80
getChunkModulesMethod · 0.80
isArrayMethod · 0.80
toIdentifierMethod · 0.80
getModuleIdMethod · 0.80
isIIFEMethod · 0.80
hasRuntimeMethod · 0.80
getPathMethod · 0.80

Tested by

no test coverage detected