* 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, runtimeTemplate, chunk, moduleGraph },
{ options, compilation }
)
| 132 | * @returns {Source} source with library export |
| 133 | */ |
| 134 | render( |
| 135 | source, |
| 136 | { chunkGraph, runtimeTemplate, chunk, moduleGraph }, |
| 137 | { options, compilation } |
| 138 | ) { |
| 139 | const modules = chunkGraph |
| 140 | .getChunkModules(chunk) |
| 141 | .filter( |
| 142 | (m) => |
| 143 | m instanceof ExternalModule && |
| 144 | (m.externalType === "umd" || m.externalType === "umd2") |
| 145 | ); |
| 146 | let externals = /** @type {ExternalModule[]} */ (modules); |
| 147 | /** @type {ExternalModule[]} */ |
| 148 | const optionalExternals = []; |
| 149 | /** @type {ExternalModule[]} */ |
| 150 | let requiredExternals = []; |
| 151 | if (this.optionalAmdExternalAsGlobal) { |
| 152 | for (const m of externals) { |
| 153 | if (m.isOptional(moduleGraph)) { |
| 154 | optionalExternals.push(m); |
| 155 | } else { |
| 156 | requiredExternals.push(m); |
| 157 | } |
| 158 | } |
| 159 | externals = [...requiredExternals, ...optionalExternals]; |
| 160 | } else { |
| 161 | requiredExternals = externals; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns the replaced keys. |
| 166 | * @param {string} str the string to replace |
| 167 | * @returns {string} the replaced keys |
| 168 | */ |
| 169 | const replaceKeys = (str) => |
| 170 | compilation.getPath(str, { |
| 171 | chunk |
| 172 | }); |
| 173 | |
| 174 | /** |
| 175 | * Externals deps array. |
| 176 | * @param {ExternalModule[]} modules external modules |
| 177 | * @returns {string} result |
| 178 | */ |
| 179 | const externalsDepsArray = (modules) => |
| 180 | `[${replaceKeys( |
| 181 | modules |
| 182 | .map((m) => |
| 183 | JSON.stringify( |
| 184 | typeof m.request === "object" |
| 185 | ? /** @type {RequestRecord} */ |
| 186 | (m.request).amd |
| 187 | : m.request |
| 188 | ) |
| 189 | ) |
| 190 | .join(", ") |
| 191 | )}]`; |
no test coverage detected