Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): remove Webpack Stats.toJson usag…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
clydin authored and alan-agius4 committed Mar 15, 2021
1 parent 3affd28 commit 699b641
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const init: any = (config: any, emitter: any) => {
webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;

let compiler: any;
let compiler;
try {
compiler = webpack(webpackConfig);
} catch (e) {
Expand Down Expand Up @@ -200,11 +200,10 @@ const init: any = (config: any, emitter: any) => {

let lastCompilationHash: string | undefined;
const statsConfig = getWebpackStatsConfig();
compiler.hooks.done.tap('karma', (stats: any) => {
if (stats.compilation.errors.length > 0) {
const json = stats.toJson(config.stats);
compiler.hooks.done.tap('karma', (stats) => {
if (stats.hasErrors()) {
// Print compilation errors.
logger.error(statsErrorsToString(json, statsConfig));
logger.error(statsErrorsToString(stats.compilation, statsConfig));
lastCompilationHash = undefined;
// Emit a failure build event if there are compilation errors.
failureCb();
Expand Down

0 comments on commit 699b641

Please sign in to comment.