* Creates a child compiler. * @param {Compilation} compilation the compilation * @param {string} compilerName the compiler's name * @param {number} compilerIndex the compiler's index * @param {Partial<OutputOptions>=} outputOptions the output options * @param {Plugins=} plugins the plugins
( compilation, compilerName, compilerIndex, outputOptions, plugins )
| 1260 | * @returns {Compiler} a child compiler |
| 1261 | */ |
| 1262 | createChildCompiler( |
| 1263 | compilation, |
| 1264 | compilerName, |
| 1265 | compilerIndex, |
| 1266 | outputOptions, |
| 1267 | plugins |
| 1268 | ) { |
| 1269 | const childCompiler = new Compiler(this.context, { |
| 1270 | ...this.options, |
| 1271 | output: { |
| 1272 | ...this.options.output, |
| 1273 | ...outputOptions |
| 1274 | } |
| 1275 | }); |
| 1276 | childCompiler.name = compilerName; |
| 1277 | childCompiler.outputPath = this.outputPath; |
| 1278 | childCompiler.inputFileSystem = this.inputFileSystem; |
| 1279 | childCompiler.outputFileSystem = null; |
| 1280 | childCompiler.resolverFactory = this.resolverFactory; |
| 1281 | childCompiler.modifiedFiles = this.modifiedFiles; |
| 1282 | childCompiler.removedFiles = this.removedFiles; |
| 1283 | childCompiler.fileTimestamps = this.fileTimestamps; |
| 1284 | childCompiler.contextTimestamps = this.contextTimestamps; |
| 1285 | childCompiler.fsStartTime = this.fsStartTime; |
| 1286 | childCompiler.cache = this.cache; |
| 1287 | childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`; |
| 1288 | childCompiler._backCompat = this._backCompat; |
| 1289 | |
| 1290 | const relativeCompilerName = makePathsRelative( |
| 1291 | this.context, |
| 1292 | compilerName, |
| 1293 | this.root |
| 1294 | ); |
| 1295 | if (!this.records[relativeCompilerName]) { |
| 1296 | this.records[relativeCompilerName] = []; |
| 1297 | } |
| 1298 | if (this.records[relativeCompilerName][compilerIndex]) { |
| 1299 | childCompiler.records = |
| 1300 | /** @type {Records} */ |
| 1301 | (this.records[relativeCompilerName][compilerIndex]); |
| 1302 | } else { |
| 1303 | this.records[relativeCompilerName].push((childCompiler.records = {})); |
| 1304 | } |
| 1305 | |
| 1306 | childCompiler.parentCompilation = compilation; |
| 1307 | childCompiler.root = this.root; |
| 1308 | if (Array.isArray(plugins)) { |
| 1309 | for (const plugin of plugins) { |
| 1310 | if (typeof plugin === "function") { |
| 1311 | /** @type {WebpackPluginFunction} */ |
| 1312 | (plugin).call(childCompiler, childCompiler); |
| 1313 | } else if (plugin) { |
| 1314 | plugin.apply(childCompiler); |
| 1315 | } |
| 1316 | } |
| 1317 | } |
| 1318 | for (const name in this.hooks) { |
| 1319 | if ( |