Skip to content

Commit a54018d

Browse files
alan-agius4dgp1130
authored andcommittedMay 20, 2022
fix(@angular-devkit/build-angular): add debugging and timing information in JavaScript and CSS optimization plugins
This can be useful to debug slow builds. Example of output ``` LOG from build-angular.JavaScriptOptimizerPlugin <t> optimize asset: runtime.ad5c30339e926c89.js: 221.959564 ms <t> optimize asset: polyfills.ec3ffae5bac27204.js: 1071.080092 ms <t> optimize asset: main.aa8a15155ca2133f.js: 3391.588635 ms <t> optimize js assets: 3483.799739 ms LOG from build-angular.CssOptimizerPlugin <t> optimize asset: styles.d251c5bf54715558.css: 26.569907 ms <t> optimize css assets: 34.441737 ms ``` ``` LOG from build-angular.JavaScriptOptimizerPlugin <i> polyfills.ec3ffae5bac27204.js restored from cache. <i> runtime.ad5c30339e926c89.js restored from cache. <t> optimize asset: main.69fb55a243b46bfa.js: 2618.5191210000003 ms <t> optimize js assets: 2721.226144 ms LOG from build-angular.CssOptimizerPlugin <i> styles.d251c5bf54715558.css restored from cache. <t> optimize css assets: 12.149169 ms ``` (cherry picked from commit 6cbb941)
1 parent 7ffa2f2 commit a54018d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

‎packages/angular_devkit/build_angular/src/webpack/plugins/css-optimizer-plugin.ts

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export class CssOptimizerPlugin {
4040
const { OriginalSource, SourceMapSource } = compiler.webpack.sources;
4141

4242
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
43+
const logger = compilation.getLogger('build-angular.CssOptimizerPlugin');
44+
4345
compilation.hooks.processAssets.tapPromise(
4446
{
4547
name: PLUGIN_NAME,
@@ -48,6 +50,7 @@ export class CssOptimizerPlugin {
4850
async (compilationAssets) => {
4951
const cache = compilation.options.cache && compilation.getCache(PLUGIN_NAME);
5052

53+
logger.time('optimize css assets');
5154
for (const assetName of Object.keys(compilationAssets)) {
5255
if (!/\.(?:css|scss|sass|less|styl)$/.test(assetName)) {
5356
continue;
@@ -70,6 +73,7 @@ export class CssOptimizerPlugin {
7073
>();
7174

7275
if (cachedOutput) {
76+
logger.debug(`${name} restored from cache`);
7377
await this.addWarnings(compilation, cachedOutput.warnings);
7478
compilation.updateAsset(name, cachedOutput.source, (assetInfo) => ({
7579
...assetInfo,
@@ -82,12 +86,15 @@ export class CssOptimizerPlugin {
8286
const { source, map: inputMap } = styleAssetSource.sourceAndMap();
8387
const input = typeof source === 'string' ? source : source.toString();
8488

89+
const optimizeAssetLabel = `optimize asset: ${asset.name}`;
90+
logger.time(optimizeAssetLabel);
8591
const { code, warnings, map } = await this.optimize(
8692
input,
8793
asset.name,
8894
inputMap,
8995
this.targets,
9096
);
97+
logger.timeEnd(optimizeAssetLabel);
9198

9299
await this.addWarnings(compilation, warnings);
93100

@@ -104,6 +111,7 @@ export class CssOptimizerPlugin {
104111
warnings,
105112
});
106113
}
114+
logger.timeEnd('optimize css assets');
107115
},
108116
);
109117
});

‎packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-plugin.ts

+10
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ export class JavaScriptOptimizerPlugin {
9090
const { OriginalSource, SourceMapSource } = compiler.webpack.sources;
9191

9292
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
93+
const logger = compilation.getLogger('build-angular.JavaScriptOptimizerPlugin');
94+
9395
compilation.hooks.processAssets.tapPromise(
9496
{
9597
name: PLUGIN_NAME,
9698
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
9799
},
98100
async (compilationAssets) => {
101+
logger.time('optimize js assets');
99102
const scriptsToOptimize = [];
100103
const cache =
101104
compilation.options.cache && compilation.getCache('JavaScriptOptimizerPlugin');
@@ -123,6 +126,7 @@ export class JavaScriptOptimizerPlugin {
123126
>();
124127

125128
if (cachedOutput) {
129+
logger.debug(`${name} restored from cache`);
126130
compilation.updateAsset(name, cachedOutput.source, (assetInfo) => ({
127131
...assetInfo,
128132
minimized: true,
@@ -195,6 +199,8 @@ export class JavaScriptOptimizerPlugin {
195199
try {
196200
const tasks = [];
197201
for (const { name, code, map, cacheItem } of scriptsToOptimize) {
202+
logger.time(`optimize asset: ${name}`);
203+
198204
tasks.push(
199205
workerPool
200206
.run({
@@ -215,6 +221,8 @@ export class JavaScriptOptimizerPlugin {
215221
minimized: true,
216222
}));
217223

224+
logger.timeEnd(`optimize asset: ${name}`);
225+
218226
return cacheItem?.storePromise({
219227
source: optimizedAsset,
220228
});
@@ -233,6 +241,8 @@ export class JavaScriptOptimizerPlugin {
233241
} finally {
234242
void workerPool.destroy();
235243
}
244+
245+
logger.timeEnd('optimize js assets');
236246
},
237247
);
238248
});

0 commit comments

Comments
 (0)
Please sign in to comment.