Skip to content

Commit 699b641

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.
1 parent 3affd28 commit 699b641

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

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

170-
let compiler: any;
170+
let compiler;
171171
try {
172172
compiler = webpack(webpackConfig);
173173
} catch (e) {
@@ -200,11 +200,10 @@ const init: any = (config: any, emitter: any) => {
200200

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

0 commit comments

Comments
 (0)