@angular-devkit/build-angular 13.0.2 → 13.1.0-next.2

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.
Files changed (47) hide show
  1. package/package.json +30 -30
  2. package/src/builders/browser/index.js +4 -7
  3. package/src/builders/dev-server/index.js +0 -4
  4. package/src/builders/extract-i18n/index.js +1 -4
  5. package/src/builders/karma/index.d.ts +2 -2
  6. package/src/builders/karma/index.js +1 -7
  7. package/src/builders/server/index.js +1 -7
  8. package/src/utils/build-options.d.ts +1 -2
  9. package/src/utils/i18n-inlining.js +18 -2
  10. package/src/utils/index.d.ts +0 -1
  11. package/src/utils/index.js +0 -1
  12. package/src/utils/normalize-builder-schema.js +2 -0
  13. package/src/{webpack/configs/worker.d.ts → utils/supported-browsers.d.ts} +1 -3
  14. package/src/utils/supported-browsers.js +26 -0
  15. package/src/webpack/configs/common.d.ts +2 -2
  16. package/src/webpack/configs/common.js +132 -158
  17. package/src/webpack/configs/dev-server.d.ts +2 -2
  18. package/src/webpack/configs/dev-server.js +74 -19
  19. package/src/webpack/configs/index.d.ts +0 -6
  20. package/src/webpack/configs/index.js +0 -6
  21. package/src/webpack/configs/styles.d.ts +2 -2
  22. package/src/webpack/configs/styles.js +2 -4
  23. package/src/webpack/plugins/index.d.ts +2 -0
  24. package/src/webpack/plugins/index.js +5 -1
  25. package/src/webpack/plugins/json-stats-plugin.d.ts +13 -0
  26. package/src/webpack/plugins/json-stats-plugin.js +54 -0
  27. package/src/webpack/plugins/progress-plugin.d.ts +11 -0
  28. package/src/webpack/plugins/progress-plugin.js +38 -0
  29. package/src/webpack/plugins/transfer-size-plugin.d.ts +12 -0
  30. package/src/webpack/plugins/transfer-size-plugin.js +47 -0
  31. package/src/webpack/{configs/browser.d.ts → plugins/typescript.d.ts} +2 -2
  32. package/src/webpack/{configs → plugins}/typescript.js +5 -24
  33. package/src/webpack/utils/helpers.d.ts +15 -5
  34. package/src/webpack/utils/helpers.js +159 -34
  35. package/src/webpack/utils/stats.d.ts +8 -2
  36. package/src/webpack/utils/stats.js +66 -21
  37. package/src/utils/build-browser-features.d.ts +0 -16
  38. package/src/utils/build-browser-features.js +0 -54
  39. package/src/webpack/configs/browser.js +0 -81
  40. package/src/webpack/configs/server.d.ts +0 -14
  41. package/src/webpack/configs/server.js +0 -73
  42. package/src/webpack/configs/stats.d.ts +0 -38
  43. package/src/webpack/configs/stats.js +0 -53
  44. package/src/webpack/configs/test.d.ts +0 -10
  45. package/src/webpack/configs/test.js +0 -77
  46. package/src/webpack/configs/typescript.d.ts +0 -12
  47. package/src/webpack/configs/worker.js +0 -22
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.JsonStatsPlugin = void 0;
30
+ const fs_1 = require("fs");
31
+ const path_1 = require("path");
32
+ const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
33
+ class JsonStatsPlugin {
34
+ constructor(statsOutputPath) {
35
+ this.statsOutputPath = statsOutputPath;
36
+ }
37
+ apply(compiler) {
38
+ compiler.hooks.done.tapPromise('angular-json-stats', async (stats) => {
39
+ const { stringifyStream } = await Promise.resolve().then(() => __importStar(require('@discoveryjs/json-ext')));
40
+ const data = stats.toJson('verbose');
41
+ try {
42
+ await fs_1.promises.mkdir((0, path_1.dirname)(this.statsOutputPath), { recursive: true });
43
+ await new Promise((resolve, reject) => stringifyStream(data)
44
+ .pipe((0, fs_1.createWriteStream)(this.statsOutputPath))
45
+ .on('close', resolve)
46
+ .on('error', reject));
47
+ }
48
+ catch (error) {
49
+ (0, webpack_diagnostics_1.addError)(stats.compilation, `Unable to write stats file: ${error.message || 'unknown error'}`);
50
+ }
51
+ });
52
+ }
53
+ }
54
+ exports.JsonStatsPlugin = JsonStatsPlugin;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { ProgressPlugin as WebpackProgressPlugin } from 'webpack';
9
+ export declare class ProgressPlugin extends WebpackProgressPlugin {
10
+ constructor(platform: 'server' | 'browser');
11
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ProgressPlugin = void 0;
11
+ const webpack_1 = require("webpack");
12
+ const spinner_1 = require("../../utils/spinner");
13
+ class ProgressPlugin extends webpack_1.ProgressPlugin {
14
+ constructor(platform) {
15
+ const platformCapitalFirst = platform.replace(/^\w/, (s) => s.toUpperCase());
16
+ const spinner = new spinner_1.Spinner();
17
+ spinner.start(`Generating ${platform} application bundles (phase: setup)...`);
18
+ super({
19
+ handler: (percentage, message) => {
20
+ const phase = message ? ` (phase: ${message})` : '';
21
+ spinner.text = `Generating ${platform} application bundles${phase}...`;
22
+ switch (percentage) {
23
+ case 1:
24
+ if (spinner.isSpinning) {
25
+ spinner.succeed(`${platformCapitalFirst} application bundle generation complete.`);
26
+ }
27
+ break;
28
+ case 0:
29
+ if (!spinner.isSpinning) {
30
+ spinner.start();
31
+ }
32
+ break;
33
+ }
34
+ },
35
+ });
36
+ }
37
+ }
38
+ exports.ProgressPlugin = ProgressPlugin;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Compiler } from 'webpack';
9
+ export declare class TransferSizePlugin {
10
+ constructor();
11
+ apply(compiler: Compiler): void;
12
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TransferSizePlugin = void 0;
11
+ const util_1 = require("util");
12
+ const zlib_1 = require("zlib");
13
+ const brotliCompressAsync = (0, util_1.promisify)(zlib_1.brotliCompress);
14
+ const PLUGIN_NAME = 'angular-transfer-size-estimator';
15
+ class TransferSizePlugin {
16
+ constructor() { }
17
+ apply(compiler) {
18
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
19
+ compilation.hooks.processAssets.tapPromise({
20
+ name: PLUGIN_NAME,
21
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
22
+ }, async (compilationAssets) => {
23
+ const actions = [];
24
+ for (const assetName of Object.keys(compilationAssets)) {
25
+ if (!assetName.endsWith('.js') && !assetName.endsWith('.css')) {
26
+ continue;
27
+ }
28
+ const scriptAsset = compilation.getAsset(assetName);
29
+ if (!scriptAsset || scriptAsset.source.size() <= 0) {
30
+ continue;
31
+ }
32
+ actions.push(brotliCompressAsync(scriptAsset.source.source())
33
+ .then((result) => {
34
+ compilation.updateAsset(assetName, (s) => s, {
35
+ estimatedTransferSize: result.length,
36
+ });
37
+ })
38
+ .catch((error) => {
39
+ compilation.warnings.push(new compilation.compiler.webpack.WebpackError(`Unable to calculate estimated transfer size for '${assetName}'. Reason: ${error.message}`));
40
+ }));
41
+ }
42
+ await Promise.all(actions);
43
+ });
44
+ });
45
+ }
46
+ }
47
+ exports.TransferSizePlugin = TransferSizePlugin;
@@ -5,6 +5,6 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import * as webpack from 'webpack';
8
+ import { AngularWebpackPlugin } from '@ngtools/webpack';
9
9
  import { WebpackConfigOptions } from '../../utils/build-options';
10
- export declare function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configuration;
10
+ export declare function createIvyPlugin(wco: WebpackConfigOptions, aot: boolean, tsconfig: string): AngularWebpackPlugin;
@@ -7,7 +7,7 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.getTypescriptWorkerPlugin = exports.getTypeScriptConfig = void 0;
10
+ exports.createIvyPlugin = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
12
  const webpack_1 = require("@ngtools/webpack");
13
13
  const typescript_1 = require("typescript");
@@ -22,6 +22,9 @@ function ensureIvy(wco) {
22
22
  wco.tsConfig.options.enableIvy = true;
23
23
  }
24
24
  function createIvyPlugin(wco, aot, tsconfig) {
25
+ if (aot) {
26
+ ensureIvy(wco);
27
+ }
25
28
  const { buildOptions } = wco;
26
29
  const optimize = buildOptions.optimization.scripts;
27
30
  const compilerOptions = {
@@ -69,26 +72,4 @@ function createIvyPlugin(wco, aot, tsconfig) {
69
72
  inlineStyleFileExtension,
70
73
  });
71
74
  }
72
- function getTypeScriptConfig(wco) {
73
- const { buildOptions: { aot = false, main, polyfills }, tsConfigPath, } = wco;
74
- if (main || polyfills) {
75
- ensureIvy(wco);
76
- return {
77
- module: {
78
- rules: [
79
- {
80
- test: /\.[jt]sx?$/,
81
- loader: webpack_1.AngularWebpackLoaderPath,
82
- },
83
- ],
84
- },
85
- plugins: [createIvyPlugin(wco, aot, tsConfigPath)],
86
- };
87
- }
88
- return {};
89
- }
90
- exports.getTypeScriptConfig = getTypeScriptConfig;
91
- function getTypescriptWorkerPlugin(wco, workerTsConfigPath) {
92
- return createIvyPlugin(wco, false, workerTsConfigPath);
93
- }
94
- exports.getTypescriptWorkerPlugin = getTypescriptWorkerPlugin;
75
+ exports.createIvyPlugin = createIvyPlugin;
@@ -5,8 +5,10 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { Configuration, SourceMapDevToolPlugin } from 'webpack';
9
- import { ExtraEntryPoint, ExtraEntryPointClass } from '../../builders/browser/schema';
8
+ import type { ObjectPattern } from 'copy-webpack-plugin';
9
+ import type { Configuration, WebpackOptionsNormalized } from 'webpack';
10
+ import { AssetPatternClass, ExtraEntryPoint, ExtraEntryPointClass } from '../../builders/browser/schema';
11
+ import { WebpackConfigOptions } from '../../utils/build-options';
10
12
  export interface HashFormat {
11
13
  chunk: string;
12
14
  extract: string;
@@ -16,8 +18,16 @@ export interface HashFormat {
16
18
  export declare function getOutputHashFormat(option: string, length?: number): HashFormat;
17
19
  export declare type NormalizedEntryPoint = Required<ExtraEntryPointClass>;
18
20
  export declare function normalizeExtraEntryPoints(extraEntryPoints: ExtraEntryPoint[], defaultBundleName: string): NormalizedEntryPoint[];
19
- export declare function getSourceMapDevTool(scriptsSourceMap: boolean | undefined, stylesSourceMap: boolean | undefined, hiddenSourceMap?: boolean, inlineSourceMap?: boolean): SourceMapDevToolPlugin;
20
- export declare function isPolyfillsEntry(name: string): boolean;
21
- export declare function getWatchOptions(poll: number | undefined): NonNullable<Configuration['watchOptions']>;
22
21
  export declare function assetNameTemplateFactory(hashFormat: HashFormat): (resourcePath: string) => string;
23
22
  export declare function getInstrumentationExcludedPaths(sourceRoot: string, excludedPaths: string[]): Set<string>;
23
+ export declare function getCacheSettings(wco: WebpackConfigOptions, angularVersion: string): WebpackOptionsNormalized['cache'];
24
+ export declare function globalScriptsByBundleName(root: string, scripts: ExtraEntryPoint[]): {
25
+ bundleName: string;
26
+ inject: boolean;
27
+ paths: string[];
28
+ }[];
29
+ export declare function assetPatterns(root: string, assets: AssetPatternClass[]): ObjectPattern[];
30
+ export declare function externalizePackages(context: string, request: string | undefined, callback: (error?: Error, result?: string) => void): void;
31
+ declare type WebpackStatsOptions = Exclude<Configuration['stats'], string | boolean>;
32
+ export declare function getStatsOptions(verbose?: boolean): WebpackStatsOptions;
33
+ export {};
@@ -29,10 +29,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.getInstrumentationExcludedPaths = exports.assetNameTemplateFactory = exports.getWatchOptions = exports.isPolyfillsEntry = exports.getSourceMapDevTool = exports.normalizeExtraEntryPoints = exports.getOutputHashFormat = void 0;
32
+ exports.getStatsOptions = exports.externalizePackages = exports.assetPatterns = exports.globalScriptsByBundleName = exports.getCacheSettings = exports.getInstrumentationExcludedPaths = exports.assetNameTemplateFactory = exports.normalizeExtraEntryPoints = exports.getOutputHashFormat = void 0;
33
+ const crypto_1 = require("crypto");
34
+ const fs_1 = require("fs");
33
35
  const glob_1 = __importDefault(require("glob"));
34
36
  const path = __importStar(require("path"));
35
- const webpack_1 = require("webpack");
36
37
  function getOutputHashFormat(option, length = 20) {
37
38
  const hashFormats = {
38
39
  none: { chunk: '', extract: '', file: '', script: '' },
@@ -74,38 +75,6 @@ function normalizeExtraEntryPoints(extraEntryPoints, defaultBundleName) {
74
75
  });
75
76
  }
76
77
  exports.normalizeExtraEntryPoints = normalizeExtraEntryPoints;
77
- function getSourceMapDevTool(scriptsSourceMap, stylesSourceMap, hiddenSourceMap = false, inlineSourceMap = false) {
78
- const include = [];
79
- if (scriptsSourceMap) {
80
- include.push(/js$/);
81
- }
82
- if (stylesSourceMap) {
83
- include.push(/css$/);
84
- }
85
- return new webpack_1.SourceMapDevToolPlugin({
86
- filename: inlineSourceMap ? undefined : '[file].map',
87
- include,
88
- // We want to set sourceRoot to `webpack:///` for non
89
- // inline sourcemaps as otherwise paths to sourcemaps will be broken in browser
90
- // `webpack:///` is needed for Visual Studio breakpoints to work properly as currently
91
- // there is no way to set the 'webRoot'
92
- sourceRoot: 'webpack:///',
93
- moduleFilenameTemplate: '[resource-path]',
94
- append: hiddenSourceMap ? false : undefined,
95
- });
96
- }
97
- exports.getSourceMapDevTool = getSourceMapDevTool;
98
- function isPolyfillsEntry(name) {
99
- return name === 'polyfills';
100
- }
101
- exports.isPolyfillsEntry = isPolyfillsEntry;
102
- function getWatchOptions(poll) {
103
- return {
104
- poll,
105
- ignored: poll === undefined ? '**/$_lazy_route_resources' : 'node_modules/**',
106
- };
107
- }
108
- exports.getWatchOptions = getWatchOptions;
109
78
  function assetNameTemplateFactory(hashFormat) {
110
79
  const visitedFiles = new Map();
111
80
  return (resourcePath) => {
@@ -140,3 +109,159 @@ function getInstrumentationExcludedPaths(sourceRoot, excludedPaths) {
140
109
  return excluded;
141
110
  }
142
111
  exports.getInstrumentationExcludedPaths = getInstrumentationExcludedPaths;
112
+ function getCacheSettings(wco, angularVersion) {
113
+ const { enabled, path: cacheDirectory } = wco.buildOptions.cache;
114
+ if (enabled) {
115
+ const packageVersion = require('../../../package.json').version;
116
+ return {
117
+ type: 'filesystem',
118
+ cacheDirectory: path.join(cacheDirectory, 'angular-webpack'),
119
+ maxMemoryGenerations: 1,
120
+ // We use the versions and build options as the cache name. The Webpack configurations are too
121
+ // dynamic and shared among different build types: test, build and serve.
122
+ // None of which are "named".
123
+ name: (0, crypto_1.createHash)('sha1')
124
+ .update(angularVersion)
125
+ .update(packageVersion)
126
+ .update(wco.projectRoot)
127
+ .update(JSON.stringify(wco.tsConfig))
128
+ .update(JSON.stringify({
129
+ ...wco.buildOptions,
130
+ // Needed because outputPath changes on every build when using i18n extraction
131
+ // https://github.com/angular/angular-cli/blob/736a5f89deaca85f487b78aec9ff66d4118ceb6a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts#L264-L265
132
+ outputPath: undefined,
133
+ }))
134
+ .digest('hex'),
135
+ };
136
+ }
137
+ if (wco.buildOptions.watch) {
138
+ return {
139
+ type: 'memory',
140
+ maxGenerations: 1,
141
+ };
142
+ }
143
+ return false;
144
+ }
145
+ exports.getCacheSettings = getCacheSettings;
146
+ function globalScriptsByBundleName(root, scripts) {
147
+ return normalizeExtraEntryPoints(scripts, 'scripts').reduce((prev, curr) => {
148
+ const { bundleName, inject, input } = curr;
149
+ let resolvedPath = path.resolve(root, input);
150
+ if (!(0, fs_1.existsSync)(resolvedPath)) {
151
+ try {
152
+ resolvedPath = require.resolve(input, { paths: [root] });
153
+ }
154
+ catch {
155
+ throw new Error(`Script file ${input} does not exist.`);
156
+ }
157
+ }
158
+ const existingEntry = prev.find((el) => el.bundleName === bundleName);
159
+ if (existingEntry) {
160
+ if (existingEntry.inject && !inject) {
161
+ // All entries have to be lazy for the bundle to be lazy.
162
+ throw new Error(`The ${bundleName} bundle is mixing injected and non-injected scripts.`);
163
+ }
164
+ existingEntry.paths.push(resolvedPath);
165
+ }
166
+ else {
167
+ prev.push({
168
+ bundleName,
169
+ inject,
170
+ paths: [resolvedPath],
171
+ });
172
+ }
173
+ return prev;
174
+ }, []);
175
+ }
176
+ exports.globalScriptsByBundleName = globalScriptsByBundleName;
177
+ function assetPatterns(root, assets) {
178
+ return assets.map((asset, index) => {
179
+ // Resolve input paths relative to workspace root and add slash at the end.
180
+ // eslint-disable-next-line prefer-const
181
+ let { input, output, ignore = [], glob } = asset;
182
+ input = path.resolve(root, input).replace(/\\/g, '/');
183
+ input = input.endsWith('/') ? input : input + '/';
184
+ output = output.endsWith('/') ? output : output + '/';
185
+ if (output.startsWith('..')) {
186
+ throw new Error('An asset cannot be written to a location outside of the output path.');
187
+ }
188
+ return {
189
+ context: input,
190
+ // Now we remove starting slash to make Webpack place it from the output root.
191
+ to: output.replace(/^\//, ''),
192
+ from: glob,
193
+ noErrorOnMissing: true,
194
+ force: true,
195
+ globOptions: {
196
+ dot: true,
197
+ followSymbolicLinks: !!asset.followSymlinks,
198
+ ignore: [
199
+ '.gitkeep',
200
+ '**/.DS_Store',
201
+ '**/Thumbs.db',
202
+ // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
203
+ // causes negate patterns not to match.
204
+ // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
205
+ ...ignore,
206
+ ].map((i) => path.posix.join(input, i)),
207
+ },
208
+ priority: index,
209
+ };
210
+ });
211
+ }
212
+ exports.assetPatterns = assetPatterns;
213
+ function externalizePackages(context, request, callback) {
214
+ if (!request) {
215
+ return;
216
+ }
217
+ // Absolute & Relative paths are not externals
218
+ if (request.startsWith('.') || path.isAbsolute(request)) {
219
+ callback();
220
+ return;
221
+ }
222
+ try {
223
+ require.resolve(request, { paths: [context] });
224
+ callback(undefined, request);
225
+ }
226
+ catch {
227
+ // Node couldn't find it, so it must be user-aliased
228
+ callback();
229
+ }
230
+ }
231
+ exports.externalizePackages = externalizePackages;
232
+ function getStatsOptions(verbose = false) {
233
+ const webpackOutputOptions = {
234
+ all: false,
235
+ colors: true,
236
+ hash: true,
237
+ timings: true,
238
+ chunks: true,
239
+ builtAt: true,
240
+ warnings: true,
241
+ errors: true,
242
+ assets: true,
243
+ cachedAssets: true,
244
+ // Needed for markAsyncChunksNonInitial.
245
+ ids: true,
246
+ entrypoints: true,
247
+ };
248
+ const verboseWebpackOutputOptions = {
249
+ // The verbose output will most likely be piped to a file, so colors just mess it up.
250
+ colors: false,
251
+ usedExports: true,
252
+ optimizationBailout: true,
253
+ reasons: true,
254
+ children: true,
255
+ assets: true,
256
+ version: true,
257
+ chunkModules: true,
258
+ errorDetails: true,
259
+ moduleTrace: true,
260
+ logging: 'verbose',
261
+ modulesSpace: Infinity,
262
+ };
263
+ return verbose
264
+ ? { ...webpackOutputOptions, ...verboseWebpackOutputOptions }
265
+ : webpackOutputOptions;
266
+ }
267
+ exports.getStatsOptions = getStatsOptions;
@@ -10,13 +10,19 @@ import { logging } from '@angular-devkit/core';
10
10
  import { Configuration, StatsCompilation } from 'webpack';
11
11
  import { Schema as BrowserBuilderOptions } from '../../builders/browser/schema';
12
12
  export declare function formatSize(size: number): string;
13
- export declare type BundleStatsData = [files: string, names: string, size: number | string];
13
+ export declare type BundleStatsData = [
14
+ files: string,
15
+ names: string,
16
+ rawSize: number | string,
17
+ estimatedTransferSize: number | string
18
+ ];
14
19
  export interface BundleStats {
15
20
  initial: boolean;
16
21
  stats: BundleStatsData;
17
22
  }
18
23
  export declare function generateBundleStats(info: {
19
- size?: number;
24
+ rawSize?: number;
25
+ estimatedTransferSize?: number;
20
26
  files?: string[];
21
27
  names?: string[];
22
28
  initial?: boolean;
@@ -34,7 +34,6 @@ const core_1 = require("@angular-devkit/core");
34
34
  const path = __importStar(require("path"));
35
35
  const text_table_1 = __importDefault(require("text-table"));
36
36
  const color_1 = require("../../utils/color");
37
- const stats_1 = require("../configs/stats");
38
37
  const async_chunks_1 = require("./async-chunks");
39
38
  const helpers_1 = require("./helpers");
40
39
  function formatSize(size) {
@@ -51,35 +50,52 @@ function formatSize(size) {
51
50
  exports.formatSize = formatSize;
52
51
  function generateBundleStats(info) {
53
52
  var _a, _b, _c;
54
- const size = typeof info.size === 'number' ? info.size : '-';
53
+ const rawSize = typeof info.rawSize === 'number' ? info.rawSize : '-';
54
+ const estimatedTransferSize = typeof info.estimatedTransferSize === 'number' ? info.estimatedTransferSize : '-';
55
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 : '';
56
56
  const names = ((_c = info.names) === null || _c === void 0 ? void 0 : _c.length) ? info.names.join(', ') : '-';
57
57
  const initial = !!info.initial;
58
58
  return {
59
59
  initial,
60
- stats: [files, names, size],
60
+ stats: [files, names, rawSize, estimatedTransferSize],
61
61
  };
62
62
  }
63
63
  exports.generateBundleStats = generateBundleStats;
64
- function generateBuildStatsTable(data, colors, showTotalSize) {
64
+ function generateBuildStatsTable(data, colors, showTotalSize, showEstimatedTransferSize) {
65
65
  const g = (x) => (colors ? color_1.colors.greenBright(x) : x);
66
66
  const c = (x) => (colors ? color_1.colors.cyanBright(x) : x);
67
67
  const bold = (x) => (colors ? color_1.colors.bold(x) : x);
68
68
  const dim = (x) => (colors ? color_1.colors.dim(x) : x);
69
69
  const changedEntryChunksStats = [];
70
70
  const changedLazyChunksStats = [];
71
- let initialTotalSize = 0;
71
+ let initialTotalRawSize = 0;
72
+ let initialTotalEstimatedTransferSize;
72
73
  for (const { initial, stats } of data) {
73
- const [files, names, size] = stats;
74
- const data = [
75
- g(files),
76
- names,
77
- c(typeof size === 'number' ? formatSize(size) : size),
78
- ];
74
+ const [files, names, rawSize, estimatedTransferSize] = stats;
75
+ let data;
76
+ if (showEstimatedTransferSize) {
77
+ data = [
78
+ g(files),
79
+ names,
80
+ c(typeof rawSize === 'number' ? formatSize(rawSize) : rawSize),
81
+ c(typeof estimatedTransferSize === 'number'
82
+ ? formatSize(estimatedTransferSize)
83
+ : estimatedTransferSize),
84
+ ];
85
+ }
86
+ else {
87
+ data = [g(files), names, c(typeof rawSize === 'number' ? formatSize(rawSize) : rawSize), ''];
88
+ }
79
89
  if (initial) {
80
90
  changedEntryChunksStats.push(data);
81
- if (typeof size === 'number') {
82
- initialTotalSize += size;
91
+ if (typeof rawSize === 'number') {
92
+ initialTotalRawSize += rawSize;
93
+ }
94
+ if (showEstimatedTransferSize && typeof estimatedTransferSize === 'number') {
95
+ if (initialTotalEstimatedTransferSize === undefined) {
96
+ initialTotalEstimatedTransferSize = 0;
97
+ }
98
+ initialTotalEstimatedTransferSize += estimatedTransferSize;
83
99
  }
84
100
  }
85
101
  else {
@@ -87,12 +103,24 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
87
103
  }
88
104
  }
89
105
  const bundleInfo = [];
106
+ const baseTitles = ['Names', 'Raw Size'];
107
+ const tableAlign = ['l', 'l', 'r'];
108
+ if (showEstimatedTransferSize) {
109
+ baseTitles.push('Estimated Transfer Size');
110
+ tableAlign.push('r');
111
+ }
90
112
  // Entry chunks
91
113
  if (changedEntryChunksStats.length) {
92
- bundleInfo.push(['Initial Chunk Files', 'Names', 'Size'].map(bold), ...changedEntryChunksStats);
114
+ bundleInfo.push(['Initial Chunk Files', ...baseTitles].map(bold), ...changedEntryChunksStats);
93
115
  if (showTotalSize) {
94
116
  bundleInfo.push([]);
95
- bundleInfo.push([' ', 'Initial Total', formatSize(initialTotalSize)].map(bold));
117
+ const totalSizeElements = [' ', 'Initial Total', formatSize(initialTotalRawSize)];
118
+ if (showEstimatedTransferSize) {
119
+ totalSizeElements.push(typeof initialTotalEstimatedTransferSize === 'number'
120
+ ? formatSize(initialTotalEstimatedTransferSize)
121
+ : '-');
122
+ }
123
+ bundleInfo.push(totalSizeElements.map(bold));
96
124
  }
97
125
  }
98
126
  // Seperator
@@ -101,12 +129,12 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
101
129
  }
102
130
  // Lazy chunks
103
131
  if (changedLazyChunksStats.length) {
104
- bundleInfo.push(['Lazy Chunk Files', 'Names', 'Size'].map(bold), ...changedLazyChunksStats);
132
+ bundleInfo.push(['Lazy Chunk Files', ...baseTitles].map(bold), ...changedLazyChunksStats);
105
133
  }
106
134
  return (0, text_table_1.default)(bundleInfo, {
107
135
  hsep: dim(' | '),
108
136
  stringLength: (s) => (0, color_1.removeColor)(s).length,
109
- align: ['l', 'l', 'r'],
137
+ align: tableAlign,
110
138
  });
111
139
  }
112
140
  function generateBuildStats(hash, time, colors) {
@@ -128,6 +156,7 @@ statsConfig, bundleState) {
128
156
  const rs = (x) => (colors ? color_1.colors.reset(x) : x);
129
157
  const changedChunksStats = bundleState !== null && bundleState !== void 0 ? bundleState : [];
130
158
  let unchangedChunkNumber = 0;
159
+ let hasEstimatedTransferSizes = false;
131
160
  if (!(bundleState === null || bundleState === void 0 ? void 0 : bundleState.length)) {
132
161
  const isFirstRun = !runsCache.has(json.outputPath || '');
133
162
  for (const chunk of json.chunks) {
@@ -137,8 +166,24 @@ statsConfig, bundleState) {
137
166
  continue;
138
167
  }
139
168
  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); });
140
- const summedSize = assets === null || assets === void 0 ? void 0 : assets.filter((asset) => !asset.name.endsWith('.map')).reduce((total, asset) => total + asset.size, 0);
141
- changedChunksStats.push(generateBundleStats({ ...chunk, size: summedSize }));
169
+ let rawSize = 0;
170
+ let estimatedTransferSize;
171
+ if (assets) {
172
+ for (const asset of assets) {
173
+ if (asset.name.endsWith('.map')) {
174
+ continue;
175
+ }
176
+ rawSize += asset.size;
177
+ if (typeof asset.info.estimatedTransferSize === 'number') {
178
+ if (estimatedTransferSize === undefined) {
179
+ estimatedTransferSize = 0;
180
+ hasEstimatedTransferSizes = true;
181
+ }
182
+ estimatedTransferSize += asset.info.estimatedTransferSize;
183
+ }
184
+ }
185
+ }
186
+ changedChunksStats.push(generateBundleStats({ ...chunk, rawSize, estimatedTransferSize }));
142
187
  }
143
188
  unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
144
189
  runsCache.add(json.outputPath || '');
@@ -153,7 +198,7 @@ statsConfig, bundleState) {
153
198
  }
154
199
  return 0;
155
200
  });
156
- const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0);
201
+ const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0, hasEstimatedTransferSizes);
157
202
  // In some cases we do things outside of webpack context
158
203
  // Such us index generation, service worker augmentation etc...
159
204
  // This will correct the time and include these.
@@ -266,7 +311,7 @@ function createWebpackLoggingCallback(options, logger) {
266
311
  if (verbose) {
267
312
  logger.info(stats.toString(config.stats));
268
313
  }
269
- const rawStats = stats.toJson((0, stats_1.getWebpackStatsConfig)(false));
314
+ const rawStats = stats.toJson((0, helpers_1.getStatsOptions)(false));
270
315
  const webpackStats = {
271
316
  ...rawStats,
272
317
  chunks: (0, async_chunks_1.markAsyncChunksNonInitial)(rawStats, extraEntryPoints),