From e80ec0787351776ea345521bf3aa72d5cf28552d Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 10 Jul 2022 11:36:47 +0200 Subject: [PATCH] feat(webpack): add --env.stats to disable printing stats primarily used internally by preview-cli --- packages/webpack5/src/bin/index.ts | 19 +++++++++++-------- packages/webpack5/src/index.ts | 3 +++ .../webpack5/src/plugins/WatchStatePlugin.ts | 9 +++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/webpack5/src/bin/index.ts b/packages/webpack5/src/bin/index.ts index 87ceed551..c9dddb315 100644 --- a/packages/webpack5/src/bin/index.ts +++ b/packages/webpack5/src/bin/index.ts @@ -56,6 +56,7 @@ program env['env'] = options.env; } + env['stats'] ??= true; env['watch'] ??= options.watch; // if --env.config is passed, we'll set an environment @@ -108,13 +109,15 @@ program // Set the process exit code depending on errors process.exitCode = stats.hasErrors() ? 1 : 0; - console.log( - stats.toString({ - chunks: false, - colors: true, - errorDetails: env.verbose, - }) - ); + if (env.stats) { + console.log( + stats.toString({ + chunks: false, + colors: true, + errorDetails: env.verbose, + }) + ); + } // if webpack profile is enabled we write the stats to a JSON file if (configuration.profile || env.profile) { @@ -141,7 +144,7 @@ program }; if (options.watch) { - console.log('webpack is watching the files...'); + env.stats && console.log('webpack is watching the files...'); compiler.watch( configuration.watchOptions ?? {}, webpackCompilationCallback diff --git a/packages/webpack5/src/index.ts b/packages/webpack5/src/index.ts index 287029544..058c74b68 100644 --- a/packages/webpack5/src/index.ts +++ b/packages/webpack5/src/index.ts @@ -46,6 +46,9 @@ export interface IWebpackEnv { // enable webpack profiling profile?: boolean; + // print webpack stats (default: true) + stats?: boolean; + // misc replace?: string[] | string; watchNodeModules?: boolean; diff --git a/packages/webpack5/src/plugins/WatchStatePlugin.ts b/packages/webpack5/src/plugins/WatchStatePlugin.ts index 81a8423f9..559f2e610 100644 --- a/packages/webpack5/src/plugins/WatchStatePlugin.ts +++ b/packages/webpack5/src/plugins/WatchStatePlugin.ts @@ -22,7 +22,7 @@ export class WatchStatePlugin { callback(); if (isWatchMode) { - console.log(messages.changeDetected); + env.stats && console.log(messages.changeDetected); if (env.verbose) { if (compiler.modifiedFiles) { @@ -44,9 +44,10 @@ export class WatchStatePlugin { compiler.hooks.afterEmit.tapAsync(id, function (compilation, callback) { callback(); - console.log( - isWatchMode ? messages.startWatching : messages.compilationComplete - ); + env.stats && + console.log( + isWatchMode ? messages.startWatching : messages.compilationComplete + ); // Do not notify the CLI if the compilation failed const stats = compilation.getStats();