Skip to content

Commit d493bb5

Browse files
clydinalan-agius4
authored andcommitted
perf(@angular-devkit/build-angular): remove Webpack Stats.toJson usage in karma plugin
Webpack's `Stats.toJson` function is an expensive operation and is recommended to be avoided where possible. In the case of the karma plugin, the compilation errors can be accessed directly without the need for the function call. (cherry picked from commit 699b641)
1 parent 50ca054 commit d493bb5

File tree

1 file changed

+4
-5
lines changed
  • packages/angular_devkit/build_angular/src/webpack/plugins/karma

1 file changed

+4
-5
lines changed

packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const init: any = (config: any, emitter: any) => {
168168
webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
169169
webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;
170170

171-
let compiler: any;
171+
let compiler;
172172
try {
173173
compiler = webpack(webpackConfig);
174174
} catch (e) {
@@ -201,11 +201,10 @@ const init: any = (config: any, emitter: any) => {
201201

202202
let lastCompilationHash: string | undefined;
203203
const statsConfig = getWebpackStatsConfig();
204-
compiler.hooks.done.tap('karma', (stats: any) => {
205-
if (stats.compilation.errors.length > 0) {
206-
const json = stats.toJson(config.stats);
204+
compiler.hooks.done.tap('karma', (stats) => {
205+
if (stats.hasErrors()) {
207206
// Print compilation errors.
208-
logger.error(statsErrorsToString(json, statsConfig));
207+
logger.error(statsErrorsToString(stats.compilation, statsConfig));
209208
lastCompilationHash = undefined;
210209
// Emit a failure build event if there are compilation errors.
211210
failureCb();

0 commit comments

Comments
 (0)