MCPcopy Create free account
hub / github.com/webpack/webpack-cli / createCompiler

Method createCompiler

packages/webpack-cli/src/webpack-cli.ts:3422–3457  ·  view source on GitHub ↗
(
    options: Options,
    callback?: WebpackCallback,
  )

Source from the content-addressed store, hash-verified

3420 }
3421
3422 async createCompiler(
3423 options: Options,
3424 callback?: WebpackCallback,
3425 ): Promise<Compiler | MultiCompiler> {
3426 const { webpack } = options;
3427
3428 if (typeof options.configNodeEnv === "string") {
3429 process.env.NODE_ENV = options.configNodeEnv;
3430 }
3431
3432 const config = await this.loadConfig(options);
3433 let compiler: Compiler | MultiCompiler;
3434
3435 try {
3436 compiler = callback
3437 ? webpack(config.options, (error, stats) => {
3438 if (error && this.isValidationError(error)) {
3439 this.logger.error(error.message);
3440 process.exit(2);
3441 }
3442
3443 callback(error as Error | null, stats);
3444 })!
3445 : webpack(config.options);
3446 } catch (error) {
3447 if (this.isValidationError(error)) {
3448 this.logger.error(error.message);
3449 } else {
3450 this.logger.error(error);
3451 }
3452
3453 process.exit(2);
3454 }
3455
3456 return compiler;
3457 }
3458
3459 #needWatchStdin(compiler: Compiler | MultiCompiler): boolean {
3460 if (this.isMultipleCompiler(compiler)) {

Callers 2

WebpackCLIClass · 0.95
runWebpackMethod · 0.95

Calls 3

loadConfigMethod · 0.95
isValidationErrorMethod · 0.95
webpackFunction · 0.85

Tested by

no test coverage detected