@angular-devkit/build-angular 13.1.0-next.1 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +29 -28
- package/src/babel/presets/application.d.ts +4 -2
- package/src/babel/presets/application.js +2 -12
- package/src/babel/webpack-loader.js +21 -13
- package/src/builders/browser/index.js +3 -2
- package/src/builders/dev-server/index.js +31 -2
- package/src/builders/extract-i18n/ivy-extract-loader.js +4 -1
- package/src/utils/bundle-calculator.d.ts +6 -7
- package/src/utils/bundle-calculator.js +3 -1
- package/src/utils/environment-options.d.ts +0 -1
- package/src/utils/environment-options.js +1 -4
- package/src/utils/i18n-options.d.ts +16 -10
- package/src/utils/i18n-options.js +46 -37
- package/src/utils/index-file/augment-index-html.d.ts +5 -1
- package/src/utils/index-file/augment-index-html.js +38 -5
- package/src/utils/read-tsconfig.js +1 -4
- package/src/webpack/configs/common.js +23 -20
- package/src/webpack/configs/dev-server.js +78 -25
- package/src/webpack/configs/styles.js +21 -10
- package/src/webpack/plugins/named-chunks-plugin.d.ts +17 -0
- package/src/webpack/plugins/named-chunks-plugin.js +49 -0
- package/src/webpack/plugins/transfer-size-plugin.d.ts +12 -0
- package/src/webpack/plugins/transfer-size-plugin.js +47 -0
- package/src/webpack/utils/helpers.d.ts +2 -0
- package/src/webpack/utils/helpers.js +17 -1
- package/src/webpack/utils/stats.d.ts +10 -3
- package/src/webpack/utils/stats.js +111 -33
|
@@ -50,35 +50,81 @@ function formatSize(size) {
|
|
|
50
50
|
exports.formatSize = formatSize;
|
|
51
51
|
function generateBundleStats(info) {
|
|
52
52
|
var _a, _b, _c;
|
|
53
|
-
const
|
|
53
|
+
const rawSize = typeof info.rawSize === 'number' ? info.rawSize : '-';
|
|
54
|
+
const estimatedTransferSize = typeof info.estimatedTransferSize === 'number' ? info.estimatedTransferSize : '-';
|
|
54
55
|
const files = (_b = (_a = info.files) === null || _a === void 0 ? void 0 : _a.filter((f) => !f.endsWith('.map')).map((f) => path.basename(f)).join(', ')) !== null && _b !== void 0 ? _b : '';
|
|
55
56
|
const names = ((_c = info.names) === null || _c === void 0 ? void 0 : _c.length) ? info.names.join(', ') : '-';
|
|
56
57
|
const initial = !!info.initial;
|
|
57
58
|
return {
|
|
58
59
|
initial,
|
|
59
|
-
stats: [files, names,
|
|
60
|
+
stats: [files, names, rawSize, estimatedTransferSize],
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
exports.generateBundleStats = generateBundleStats;
|
|
63
|
-
function generateBuildStatsTable(data, colors, showTotalSize) {
|
|
64
|
+
function generateBuildStatsTable(data, colors, showTotalSize, showEstimatedTransferSize, budgetFailures) {
|
|
64
65
|
const g = (x) => (colors ? color_1.colors.greenBright(x) : x);
|
|
65
66
|
const c = (x) => (colors ? color_1.colors.cyanBright(x) : x);
|
|
67
|
+
const r = (x) => (colors ? color_1.colors.redBright(x) : x);
|
|
68
|
+
const y = (x) => (colors ? color_1.colors.yellowBright(x) : x);
|
|
66
69
|
const bold = (x) => (colors ? color_1.colors.bold(x) : x);
|
|
67
70
|
const dim = (x) => (colors ? color_1.colors.dim(x) : x);
|
|
71
|
+
const getSizeColor = (name, file, defaultColor = c) => {
|
|
72
|
+
const severity = budgets.get(name) || (file && budgets.get(file));
|
|
73
|
+
switch (severity) {
|
|
74
|
+
case 'warning':
|
|
75
|
+
return y;
|
|
76
|
+
case 'error':
|
|
77
|
+
return r;
|
|
78
|
+
default:
|
|
79
|
+
return defaultColor;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
68
82
|
const changedEntryChunksStats = [];
|
|
69
83
|
const changedLazyChunksStats = [];
|
|
70
|
-
let
|
|
84
|
+
let initialTotalRawSize = 0;
|
|
85
|
+
let initialTotalEstimatedTransferSize;
|
|
86
|
+
const budgets = new Map();
|
|
87
|
+
if (budgetFailures) {
|
|
88
|
+
for (const { label, severity } of budgetFailures) {
|
|
89
|
+
// In some cases a file can have multiple budget failures.
|
|
90
|
+
// Favor error.
|
|
91
|
+
if (label && (!budgets.has(label) || budgets.get(label) === 'warning')) {
|
|
92
|
+
budgets.set(label, severity);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
71
96
|
for (const { initial, stats } of data) {
|
|
72
|
-
const [files, names,
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
97
|
+
const [files, names, rawSize, estimatedTransferSize] = stats;
|
|
98
|
+
const getRawSizeColor = getSizeColor(names, files);
|
|
99
|
+
let data;
|
|
100
|
+
if (showEstimatedTransferSize) {
|
|
101
|
+
data = [
|
|
102
|
+
g(files),
|
|
103
|
+
names,
|
|
104
|
+
getRawSizeColor(typeof rawSize === 'number' ? formatSize(rawSize) : rawSize),
|
|
105
|
+
c(typeof estimatedTransferSize === 'number'
|
|
106
|
+
? formatSize(estimatedTransferSize)
|
|
107
|
+
: estimatedTransferSize),
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
data = [
|
|
112
|
+
g(files),
|
|
113
|
+
names,
|
|
114
|
+
getRawSizeColor(typeof rawSize === 'number' ? formatSize(rawSize) : rawSize),
|
|
115
|
+
'',
|
|
116
|
+
];
|
|
117
|
+
}
|
|
78
118
|
if (initial) {
|
|
79
119
|
changedEntryChunksStats.push(data);
|
|
80
|
-
if (typeof
|
|
81
|
-
|
|
120
|
+
if (typeof rawSize === 'number') {
|
|
121
|
+
initialTotalRawSize += rawSize;
|
|
122
|
+
}
|
|
123
|
+
if (showEstimatedTransferSize && typeof estimatedTransferSize === 'number') {
|
|
124
|
+
if (initialTotalEstimatedTransferSize === undefined) {
|
|
125
|
+
initialTotalEstimatedTransferSize = 0;
|
|
126
|
+
}
|
|
127
|
+
initialTotalEstimatedTransferSize += estimatedTransferSize;
|
|
82
128
|
}
|
|
83
129
|
}
|
|
84
130
|
else {
|
|
@@ -86,12 +132,29 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
|
|
|
86
132
|
}
|
|
87
133
|
}
|
|
88
134
|
const bundleInfo = [];
|
|
135
|
+
const baseTitles = ['Names', 'Raw Size'];
|
|
136
|
+
const tableAlign = ['l', 'l', 'r'];
|
|
137
|
+
if (showEstimatedTransferSize) {
|
|
138
|
+
baseTitles.push('Estimated Transfer Size');
|
|
139
|
+
tableAlign.push('r');
|
|
140
|
+
}
|
|
89
141
|
// Entry chunks
|
|
90
142
|
if (changedEntryChunksStats.length) {
|
|
91
|
-
bundleInfo.push(['Initial Chunk Files',
|
|
143
|
+
bundleInfo.push(['Initial Chunk Files', ...baseTitles].map(bold), ...changedEntryChunksStats);
|
|
92
144
|
if (showTotalSize) {
|
|
93
145
|
bundleInfo.push([]);
|
|
94
|
-
|
|
146
|
+
const initialSizeTotalColor = getSizeColor('bundle initial', undefined, (x) => x);
|
|
147
|
+
const totalSizeElements = [
|
|
148
|
+
' ',
|
|
149
|
+
'Initial Total',
|
|
150
|
+
initialSizeTotalColor(formatSize(initialTotalRawSize)),
|
|
151
|
+
];
|
|
152
|
+
if (showEstimatedTransferSize) {
|
|
153
|
+
totalSizeElements.push(typeof initialTotalEstimatedTransferSize === 'number'
|
|
154
|
+
? formatSize(initialTotalEstimatedTransferSize)
|
|
155
|
+
: '-');
|
|
156
|
+
}
|
|
157
|
+
bundleInfo.push(totalSizeElements.map(bold));
|
|
95
158
|
}
|
|
96
159
|
}
|
|
97
160
|
// Seperator
|
|
@@ -100,12 +163,12 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
|
|
|
100
163
|
}
|
|
101
164
|
// Lazy chunks
|
|
102
165
|
if (changedLazyChunksStats.length) {
|
|
103
|
-
bundleInfo.push(['Lazy Chunk Files',
|
|
166
|
+
bundleInfo.push(['Lazy Chunk Files', ...baseTitles].map(bold), ...changedLazyChunksStats);
|
|
104
167
|
}
|
|
105
168
|
return (0, text_table_1.default)(bundleInfo, {
|
|
106
169
|
hsep: dim(' | '),
|
|
107
170
|
stringLength: (s) => (0, color_1.removeColor)(s).length,
|
|
108
|
-
align:
|
|
171
|
+
align: tableAlign,
|
|
109
172
|
});
|
|
110
173
|
}
|
|
111
174
|
function generateBuildStats(hash, time, colors) {
|
|
@@ -118,30 +181,45 @@ function generateBuildStats(hash, time, colors) {
|
|
|
118
181
|
const runsCache = new Set();
|
|
119
182
|
function statsToString(json,
|
|
120
183
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
121
|
-
statsConfig,
|
|
184
|
+
statsConfig, budgetFailures) {
|
|
122
185
|
var _a, _b;
|
|
123
186
|
if (!((_a = json.chunks) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
124
187
|
return '';
|
|
125
188
|
}
|
|
126
189
|
const colors = statsConfig.colors;
|
|
127
190
|
const rs = (x) => (colors ? color_1.colors.reset(x) : x);
|
|
128
|
-
const changedChunksStats =
|
|
191
|
+
const changedChunksStats = [];
|
|
129
192
|
let unchangedChunkNumber = 0;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
193
|
+
let hasEstimatedTransferSizes = false;
|
|
194
|
+
const isFirstRun = !runsCache.has(json.outputPath || '');
|
|
195
|
+
for (const chunk of json.chunks) {
|
|
196
|
+
// During first build we want to display unchanged chunks
|
|
197
|
+
// but unchanged cached chunks are always marked as not rendered.
|
|
198
|
+
if (!isFirstRun && !chunk.rendered) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const assets = (_b = json.assets) === null || _b === void 0 ? void 0 : _b.filter((asset) => { var _a; return (_a = chunk.files) === null || _a === void 0 ? void 0 : _a.includes(asset.name); });
|
|
202
|
+
let rawSize = 0;
|
|
203
|
+
let estimatedTransferSize;
|
|
204
|
+
if (assets) {
|
|
205
|
+
for (const asset of assets) {
|
|
206
|
+
if (asset.name.endsWith('.map')) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
rawSize += asset.size;
|
|
210
|
+
if (typeof asset.info.estimatedTransferSize === 'number') {
|
|
211
|
+
if (estimatedTransferSize === undefined) {
|
|
212
|
+
estimatedTransferSize = 0;
|
|
213
|
+
hasEstimatedTransferSizes = true;
|
|
214
|
+
}
|
|
215
|
+
estimatedTransferSize += asset.info.estimatedTransferSize;
|
|
216
|
+
}
|
|
137
217
|
}
|
|
138
|
-
const assets = (_b = json.assets) === null || _b === void 0 ? void 0 : _b.filter((asset) => { var _a; return (_a = chunk.files) === null || _a === void 0 ? void 0 : _a.includes(asset.name); });
|
|
139
|
-
const summedSize = assets === null || assets === void 0 ? void 0 : assets.filter((asset) => !asset.name.endsWith('.map')).reduce((total, asset) => total + asset.size, 0);
|
|
140
|
-
changedChunksStats.push(generateBundleStats({ ...chunk, size: summedSize }));
|
|
141
218
|
}
|
|
142
|
-
|
|
143
|
-
runsCache.add(json.outputPath || '');
|
|
219
|
+
changedChunksStats.push(generateBundleStats({ ...chunk, rawSize, estimatedTransferSize }));
|
|
144
220
|
}
|
|
221
|
+
unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
|
|
222
|
+
runsCache.add(json.outputPath || '');
|
|
145
223
|
// Sort chunks by size in descending order
|
|
146
224
|
changedChunksStats.sort((a, b) => {
|
|
147
225
|
if (a.stats[2] > b.stats[2]) {
|
|
@@ -152,7 +230,7 @@ statsConfig, bundleState) {
|
|
|
152
230
|
}
|
|
153
231
|
return 0;
|
|
154
232
|
});
|
|
155
|
-
const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0);
|
|
233
|
+
const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0, hasEstimatedTransferSizes, budgetFailures);
|
|
156
234
|
// In some cases we do things outside of webpack context
|
|
157
235
|
// Such us index generation, service worker augmentation etc...
|
|
158
236
|
// This will correct the time and include these.
|
|
@@ -274,8 +352,8 @@ function createWebpackLoggingCallback(options, logger) {
|
|
|
274
352
|
};
|
|
275
353
|
}
|
|
276
354
|
exports.createWebpackLoggingCallback = createWebpackLoggingCallback;
|
|
277
|
-
function webpackStatsLogger(logger, json, config,
|
|
278
|
-
logger.info(statsToString(json, config.stats,
|
|
355
|
+
function webpackStatsLogger(logger, json, config, budgetFailures) {
|
|
356
|
+
logger.info(statsToString(json, config.stats, budgetFailures));
|
|
279
357
|
if (statsHasWarnings(json)) {
|
|
280
358
|
logger.warn(statsWarningsToString(json, config.stats));
|
|
281
359
|
}
|