(rawOptions, compilerIndex)
| 79 | * @returns {Compiler} a compiler |
| 80 | */ |
| 81 | const createCompiler = (rawOptions, compilerIndex) => { |
| 82 | let options = getNormalizedWebpackOptions(rawOptions); |
| 83 | applyWebpackOptionsBaseDefaults(options); |
| 84 | |
| 85 | /** @type {WebpackOptionsInterception=} */ |
| 86 | let interception; |
| 87 | ({ options, interception } = applyWebpackOptionsInterception(options)); |
| 88 | |
| 89 | const compiler = new Compiler( |
| 90 | /** @type {string} */ (options.context), |
| 91 | options |
| 92 | ); |
| 93 | new NodeEnvironmentPlugin({ |
| 94 | infrastructureLogging: options.infrastructureLogging |
| 95 | }).apply(compiler); |
| 96 | if (Array.isArray(options.plugins)) { |
| 97 | for (const plugin of options.plugins) { |
| 98 | if (typeof plugin === "function") { |
| 99 | /** @type {WebpackPluginFunction} */ |
| 100 | (plugin).call(compiler, compiler); |
| 101 | } else if (plugin) { |
| 102 | plugin.apply(compiler); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | const resolvedDefaultOptions = applyWebpackOptionsDefaults( |
| 107 | options, |
| 108 | compilerIndex |
| 109 | ); |
| 110 | if (resolvedDefaultOptions.platform) { |
| 111 | compiler.platform = resolvedDefaultOptions.platform; |
| 112 | } |
| 113 | if (options.validate) { |
| 114 | compiler.hooks.validate.call(); |
| 115 | } |
| 116 | compiler.hooks.environment.call(); |
| 117 | compiler.hooks.afterEnvironment.call(); |
| 118 | new WebpackOptionsApply().process( |
| 119 | /** @type {WebpackOptionsNormalizedWithDefaults} */ |
| 120 | (options), |
| 121 | compiler, |
| 122 | interception |
| 123 | ); |
| 124 | compiler.hooks.initialize.call(); |
| 125 | return compiler; |
| 126 | }; |
| 127 | |
| 128 | /** |
| 129 | * Returns array of options. |
no test coverage detected