@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
@@ -30,25 +30,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.getCommonConfig = void 0;
33
+ const webpack_1 = require("@ngtools/webpack");
33
34
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
34
- const crypto_1 = require("crypto");
35
- const fs_1 = require("fs");
36
35
  const path = __importStar(require("path"));
37
36
  const typescript_1 = require("typescript");
38
- const webpack_1 = require("webpack");
39
- const utils_1 = require("../../utils");
37
+ const webpack_2 = require("webpack");
38
+ const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
40
39
  const environment_options_1 = require("../../utils/environment-options");
41
40
  const load_esm_1 = require("../../utils/load-esm");
42
- const spinner_1 = require("../../utils/spinner");
43
- const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
44
41
  const plugins_1 = require("../plugins");
45
- const javascript_optimizer_plugin_1 = require("../plugins/javascript-optimizer-plugin");
42
+ const progress_plugin_1 = require("../plugins/progress-plugin");
43
+ const transfer_size_plugin_1 = require("../plugins/transfer-size-plugin");
44
+ const typescript_2 = require("../plugins/typescript");
46
45
  const helpers_1 = require("../utils/helpers");
47
46
  // eslint-disable-next-line max-lines-per-function
48
47
  async function getCommonConfig(wco) {
49
48
  var _a, _b;
50
- const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot } = wco;
51
- const { cache, codeCoverage, codeCoverageExclude = [], platform = 'browser', sourceMap: { styles: stylesSourceMap, scripts: scriptsSourceMap, vendor: vendorSourceMap }, optimization: { styles: stylesOptimization, scripts: scriptsOptimization }, } = buildOptions;
49
+ const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot, tsConfigPath } = wco;
50
+ const { cache, codeCoverage, crossOrigin = 'none', platform = 'browser', aot = true, codeCoverageExclude = [], main, polyfills, sourceMap: { styles: stylesSourceMap, scripts: scriptsSourceMap, vendor: vendorSourceMap, hidden: hiddenSourceMap, }, optimization: { styles: stylesOptimization, scripts: scriptsOptimization }, commonChunk, vendorChunk, subresourceIntegrity, verbose, poll, webWorkerTsConfig, externalDependencies = [], allowedCommonJsDependencies, bundleDependencies, } = buildOptions;
51
+ const isPlatformServer = buildOptions.platform === 'server';
52
52
  const extraPlugins = [];
53
53
  const extraRules = [];
54
54
  const entryPoints = {};
@@ -61,34 +61,18 @@ async function getCommonConfig(wco) {
61
61
  const { GLOBAL_DEFS_FOR_TERSER, GLOBAL_DEFS_FOR_TERSER_WITH_AOT, VERSION: NG_VERSION, } = (compilerCliModule.GLOBAL_DEFS_FOR_TERSER ? compilerCliModule : compilerCliModule.default);
62
62
  // determine hashing format
63
63
  const hashFormat = (0, helpers_1.getOutputHashFormat)(buildOptions.outputHashing || 'none');
64
- const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot);
65
64
  if (buildOptions.progress) {
66
- const spinner = new spinner_1.Spinner();
67
- spinner.start(`Generating ${platform} application bundles (phase: setup)...`);
68
- extraPlugins.push(new webpack_1.ProgressPlugin({
69
- handler: (percentage, message) => {
70
- const phase = message ? ` (phase: ${message})` : '';
71
- spinner.text = `Generating ${platform} application bundles${phase}...`;
72
- switch (percentage) {
73
- case 1:
74
- if (spinner.isSpinning) {
75
- spinner.succeed(`${platform.replace(/^\w/, (s) => s.toUpperCase())} application bundle generation complete.`);
76
- }
77
- break;
78
- case 0:
79
- if (!spinner.isSpinning) {
80
- spinner.start();
81
- }
82
- break;
83
- }
84
- },
85
- }));
65
+ extraPlugins.push(new progress_plugin_1.ProgressPlugin(platform));
86
66
  }
87
67
  if (buildOptions.main) {
88
68
  const mainPath = path.resolve(root, buildOptions.main);
89
69
  entryPoints['main'] = [mainPath];
90
70
  }
91
- if (platform !== 'server') {
71
+ if (isPlatformServer) {
72
+ // Fixes Critical dependency: the request of a dependency is an expression
73
+ extraPlugins.push(new webpack_2.ContextReplacementPlugin(/@?hapi|express[\\/]/));
74
+ }
75
+ if (!isPlatformServer) {
92
76
  if (buildOptions.polyfills) {
93
77
  const projectPolyfills = path.resolve(root, buildOptions.polyfills);
94
78
  if (entryPoints['polyfills']) {
@@ -109,89 +93,34 @@ async function getCommonConfig(wco) {
109
93
  }
110
94
  }
111
95
  if (environment_options_1.profilingEnabled) {
112
- extraPlugins.push(new webpack_1.debug.ProfilingPlugin({
96
+ extraPlugins.push(new webpack_2.debug.ProfilingPlugin({
113
97
  outputPath: path.resolve(root, 'chrome-profiler-events.json'),
114
98
  }));
115
99
  }
100
+ if (allowedCommonJsDependencies) {
101
+ // When this is not defined it means the builder doesn't support showing common js usages.
102
+ // When it does it will be an array.
103
+ extraPlugins.push(new plugins_1.CommonJsUsageWarnPlugin({
104
+ allowedDependencies: allowedCommonJsDependencies,
105
+ }));
106
+ }
116
107
  // process global scripts
117
- const globalScriptsByBundleName = (0, helpers_1.normalizeExtraEntryPoints)(buildOptions.scripts, 'scripts').reduce((prev, curr) => {
118
- const { bundleName, inject, input } = curr;
119
- let resolvedPath = path.resolve(root, input);
120
- if (!(0, fs_1.existsSync)(resolvedPath)) {
121
- try {
122
- resolvedPath = require.resolve(input, { paths: [root] });
123
- }
124
- catch {
125
- throw new Error(`Script file ${input} does not exist.`);
126
- }
127
- }
128
- const existingEntry = prev.find((el) => el.bundleName === bundleName);
129
- if (existingEntry) {
130
- if (existingEntry.inject && !inject) {
131
- // All entries have to be lazy for the bundle to be lazy.
132
- throw new Error(`The ${bundleName} bundle is mixing injected and non-injected scripts.`);
133
- }
134
- existingEntry.paths.push(resolvedPath);
135
- }
136
- else {
137
- prev.push({
138
- bundleName,
139
- inject,
140
- paths: [resolvedPath],
141
- });
142
- }
143
- return prev;
144
- }, []);
145
108
  // Add a new asset for each entry.
146
- for (const script of globalScriptsByBundleName) {
109
+ for (const { bundleName, inject, paths } of (0, helpers_1.globalScriptsByBundleName)(root, buildOptions.scripts)) {
147
110
  // Lazy scripts don't get a hash, otherwise they can't be loaded by name.
148
- const hash = script.inject ? hashFormat.script : '';
149
- const bundleName = script.bundleName;
111
+ const hash = inject ? hashFormat.script : '';
150
112
  extraPlugins.push(new plugins_1.ScriptsWebpackPlugin({
151
113
  name: bundleName,
152
114
  sourceMap: scriptsSourceMap,
115
+ scripts: paths,
153
116
  filename: `${path.basename(bundleName)}${hash}.js`,
154
- scripts: script.paths,
155
117
  basePath: projectRoot,
156
118
  }));
157
119
  }
158
120
  // process asset entries
159
121
  if (buildOptions.assets.length) {
160
- const copyWebpackPluginPatterns = buildOptions.assets.map((asset, index) => {
161
- // Resolve input paths relative to workspace root and add slash at the end.
162
- // eslint-disable-next-line prefer-const
163
- let { input, output, ignore = [], glob } = asset;
164
- input = path.resolve(root, input).replace(/\\/g, '/');
165
- input = input.endsWith('/') ? input : input + '/';
166
- output = output.endsWith('/') ? output : output + '/';
167
- if (output.startsWith('..')) {
168
- throw new Error('An asset cannot be written to a location outside of the output path.');
169
- }
170
- return {
171
- context: input,
172
- // Now we remove starting slash to make Webpack place it from the output root.
173
- to: output.replace(/^\//, ''),
174
- from: glob,
175
- noErrorOnMissing: true,
176
- force: true,
177
- globOptions: {
178
- dot: true,
179
- followSymbolicLinks: !!asset.followSymlinks,
180
- ignore: [
181
- '.gitkeep',
182
- '**/.DS_Store',
183
- '**/Thumbs.db',
184
- // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
185
- // causes negate patterns not to match.
186
- // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
187
- ...ignore,
188
- ].map((i) => path.posix.join(input, i)),
189
- },
190
- priority: index,
191
- };
192
- });
193
122
  extraPlugins.push(new copy_webpack_plugin_1.default({
194
- patterns: copyWebpackPluginPatterns,
123
+ patterns: (0, helpers_1.assetPatterns)(root, buildOptions.assets),
195
124
  }));
196
125
  }
197
126
  if (buildOptions.showCircularDependencies) {
@@ -212,26 +141,33 @@ async function getCommonConfig(wco) {
212
141
  skipChildCompilers: true,
213
142
  }));
214
143
  }
144
+ if (scriptsSourceMap || stylesSourceMap) {
145
+ const include = [];
146
+ if (scriptsSourceMap) {
147
+ include.push(/js$/);
148
+ }
149
+ if (stylesSourceMap) {
150
+ include.push(/css$/);
151
+ }
152
+ extraPlugins.push(new webpack_2.SourceMapDevToolPlugin({
153
+ filename: '[file].map',
154
+ include,
155
+ // We want to set sourceRoot to `webpack:///` for non
156
+ // inline sourcemaps as otherwise paths to sourcemaps will be broken in browser
157
+ // `webpack:///` is needed for Visual Studio breakpoints to work properly as currently
158
+ // there is no way to set the 'webRoot'
159
+ sourceRoot: 'webpack:///',
160
+ moduleFilenameTemplate: '[resource-path]',
161
+ append: hiddenSourceMap ? false : undefined,
162
+ }));
163
+ }
215
164
  if (buildOptions.statsJson) {
216
- extraPlugins.push(new (class {
217
- apply(compiler) {
218
- compiler.hooks.done.tapPromise('angular-cli-stats', async (stats) => {
219
- const { stringifyStream } = await Promise.resolve().then(() => __importStar(require('@discoveryjs/json-ext')));
220
- const data = stats.toJson('verbose');
221
- const statsOutputPath = path.resolve(root, buildOptions.outputPath, 'stats.json');
222
- try {
223
- await fs_1.promises.mkdir(path.dirname(statsOutputPath), { recursive: true });
224
- await new Promise((resolve, reject) => stringifyStream(data)
225
- .pipe((0, fs_1.createWriteStream)(statsOutputPath))
226
- .on('close', resolve)
227
- .on('error', reject));
228
- }
229
- catch (error) {
230
- (0, webpack_diagnostics_1.addError)(stats.compilation, `Unable to write stats file: ${error.message || 'unknown error'}`);
231
- }
232
- });
233
- }
234
- })());
165
+ extraPlugins.push(new plugins_1.JsonStatsPlugin(path.resolve(root, buildOptions.outputPath, 'stats.json')));
166
+ }
167
+ if (subresourceIntegrity) {
168
+ extraPlugins.push(new webpack_subresource_integrity_1.SubresourceIntegrityPlugin({
169
+ hashFuncNames: ['sha384'],
170
+ }));
235
171
  }
236
172
  if (scriptsSourceMap || stylesSourceMap) {
237
173
  extraRules.push({
@@ -251,22 +187,46 @@ async function getCommonConfig(wco) {
251
187
  },
252
188
  });
253
189
  }
190
+ if (main || polyfills) {
191
+ extraRules.push({
192
+ test: /\.[cm]?[tj]sx?$/,
193
+ loader: webpack_1.AngularWebpackLoaderPath,
194
+ });
195
+ extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, aot, tsConfigPath));
196
+ }
197
+ if (webWorkerTsConfig) {
198
+ extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, false, path.resolve(wco.root, webWorkerTsConfig)));
199
+ }
254
200
  const extraMinimizers = [];
255
201
  if (scriptsOptimization) {
256
- extraMinimizers.push(new javascript_optimizer_plugin_1.JavaScriptOptimizerPlugin({
202
+ extraMinimizers.push(new plugins_1.JavaScriptOptimizerPlugin({
257
203
  define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
258
204
  sourcemap: scriptsSourceMap,
259
205
  target: wco.scriptTarget,
260
- keepNames: !environment_options_1.allowMangle || platform === 'server',
206
+ keepNames: !environment_options_1.allowMangle || isPlatformServer,
261
207
  removeLicenses: buildOptions.extractLicenses,
262
208
  advanced: buildOptions.buildOptimizer,
263
209
  }));
264
210
  }
211
+ if (platform === 'browser' && (scriptsOptimization || stylesOptimization.minify)) {
212
+ extraMinimizers.push(new transfer_size_plugin_1.TransferSizePlugin());
213
+ }
214
+ const externals = [...externalDependencies];
215
+ if (isPlatformServer && !bundleDependencies) {
216
+ externals.push(({ context, request }, callback) => (0, helpers_1.externalizePackages)(context !== null && context !== void 0 ? context : wco.projectRoot, request, callback));
217
+ }
218
+ let crossOriginLoading = false;
219
+ if (subresourceIntegrity && crossOrigin === 'none') {
220
+ crossOriginLoading = 'anonymous';
221
+ }
222
+ else if (crossOrigin !== 'none') {
223
+ crossOriginLoading = crossOrigin;
224
+ }
265
225
  return {
266
226
  mode: scriptsOptimization || stylesOptimization.minify ? 'production' : 'development',
267
227
  devtool: false,
268
228
  target: [
269
- platform === 'server' ? 'node' : 'web',
229
+ isPlatformServer ? 'node' : 'web',
270
230
  tsConfig.options.target === typescript_1.ScriptTarget.ES5 ? 'es5' : 'es2015',
271
231
  ],
272
232
  profile: buildOptions.statsJson,
@@ -275,12 +235,17 @@ async function getCommonConfig(wco) {
275
235
  extensions: ['.ts', '.tsx', '.mjs', '.js'],
276
236
  symlinks: !buildOptions.preserveSymlinks,
277
237
  modules: [tsConfig.options.baseUrl || projectRoot, 'node_modules'],
238
+ mainFields: isPlatformServer
239
+ ? ['es2015', 'module', 'main']
240
+ : ['es2020', 'es2015', 'browser', 'module', 'main'],
241
+ conditionNames: isPlatformServer ? ['es2015', '...'] : ['es2020', 'es2015', '...'],
278
242
  },
279
243
  resolveLoader: {
280
244
  symlinks: !buildOptions.preserveSymlinks,
281
245
  },
282
246
  context: root,
283
247
  entry: entryPoints,
248
+ externals,
284
249
  output: {
285
250
  uniqueName: projectName,
286
251
  hashFunction: 'xxhash64',
@@ -289,9 +254,16 @@ async function getCommonConfig(wco) {
289
254
  publicPath: (_b = buildOptions.deployUrl) !== null && _b !== void 0 ? _b : '',
290
255
  filename: `[name]${hashFormat.chunk}.js`,
291
256
  chunkFilename: `[name]${hashFormat.chunk}.js`,
257
+ libraryTarget: isPlatformServer ? 'commonjs' : undefined,
258
+ crossOriginLoading,
259
+ trustedTypes: 'angular#bundler',
260
+ scriptType: 'module',
292
261
  },
293
262
  watch: buildOptions.watch,
294
- watchOptions: (0, helpers_1.getWatchOptions)(buildOptions.poll),
263
+ watchOptions: {
264
+ poll,
265
+ ignored: poll === undefined ? undefined : 'node_modules/**',
266
+ },
295
267
  performance: {
296
268
  hints: false,
297
269
  },
@@ -307,6 +279,14 @@ async function getCommonConfig(wco) {
307
279
  module: {
308
280
  // Show an error for missing exports instead of a warning.
309
281
  strictExportPresence: true,
282
+ parser: webWorkerTsConfig === undefined
283
+ ? {
284
+ javascript: {
285
+ worker: false,
286
+ url: false,
287
+ },
288
+ }
289
+ : undefined,
310
290
  rules: [
311
291
  {
312
292
  // Mark files inside `rxjs/add` as containing side effects.
@@ -342,54 +322,48 @@ async function getCommonConfig(wco) {
342
322
  ],
343
323
  },
344
324
  experiments: {
325
+ backCompat: false,
345
326
  syncWebAssembly: true,
346
327
  asyncWebAssembly: true,
347
328
  },
348
329
  infrastructureLogging: {
349
- level: buildOptions.verbose ? 'verbose' : 'error',
330
+ level: verbose ? 'verbose' : 'error',
350
331
  },
351
- cache: getCacheSettings(wco, buildBrowserFeatures.supportedBrowsers, NG_VERSION.full),
332
+ stats: (0, helpers_1.getStatsOptions)(verbose),
333
+ cache: (0, helpers_1.getCacheSettings)(wco, NG_VERSION.full),
352
334
  optimization: {
353
335
  minimizer: extraMinimizers,
354
336
  moduleIds: 'deterministic',
355
337
  chunkIds: buildOptions.namedChunks ? 'named' : 'deterministic',
356
338
  emitOnErrors: false,
339
+ runtimeChunk: isPlatformServer ? false : 'single',
340
+ splitChunks: {
341
+ maxAsyncRequests: Infinity,
342
+ cacheGroups: {
343
+ default: !!commonChunk && {
344
+ chunks: 'async',
345
+ minChunks: 2,
346
+ priority: 10,
347
+ },
348
+ common: !!commonChunk && {
349
+ name: 'common',
350
+ chunks: 'async',
351
+ minChunks: 2,
352
+ enforce: true,
353
+ priority: 5,
354
+ },
355
+ vendors: false,
356
+ defaultVendors: !!vendorChunk && {
357
+ name: 'vendor',
358
+ chunks: (chunk) => chunk.name === 'main',
359
+ enforce: true,
360
+ test: /[\\/]node_modules[\\/]/,
361
+ },
362
+ },
363
+ },
357
364
  },
358
- plugins: [new plugins_1.DedupeModuleResolvePlugin({ verbose: buildOptions.verbose }), ...extraPlugins],
365
+ plugins: [new plugins_1.DedupeModuleResolvePlugin({ verbose }), ...extraPlugins],
366
+ node: false,
359
367
  };
360
368
  }
361
369
  exports.getCommonConfig = getCommonConfig;
362
- function getCacheSettings(wco, supportedBrowsers, angularVersion) {
363
- const { enabled, path: cacheDirectory } = wco.buildOptions.cache;
364
- if (enabled) {
365
- const packageVersion = require('../../../package.json').version;
366
- return {
367
- type: 'filesystem',
368
- cacheDirectory: path.join(cacheDirectory, 'angular-webpack'),
369
- maxMemoryGenerations: 1,
370
- // We use the versions and build options as the cache name. The Webpack configurations are too
371
- // dynamic and shared among different build types: test, build and serve.
372
- // None of which are "named".
373
- name: (0, crypto_1.createHash)('sha1')
374
- .update(angularVersion)
375
- .update(packageVersion)
376
- .update(wco.projectRoot)
377
- .update(JSON.stringify(wco.tsConfig))
378
- .update(JSON.stringify({
379
- ...wco.buildOptions,
380
- // Needed because outputPath changes on every build when using i18n extraction
381
- // https://github.com/angular/angular-cli/blob/736a5f89deaca85f487b78aec9ff66d4118ceb6a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts#L264-L265
382
- outputPath: undefined,
383
- }))
384
- .update(supportedBrowsers.join(''))
385
- .digest('hex'),
386
- };
387
- }
388
- if (wco.buildOptions.watch) {
389
- return {
390
- type: 'memory',
391
- maxGenerations: 1,
392
- };
393
- }
394
- return false;
395
- }
@@ -6,9 +6,9 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { logging } from '@angular-devkit/core';
9
- import * as webpack from 'webpack';
9
+ import { Configuration } from 'webpack';
10
10
  import { WebpackConfigOptions, WebpackDevServerOptions } from '../../utils/build-options';
11
- export declare function getDevServerConfig(wco: WebpackConfigOptions<WebpackDevServerOptions>): Promise<webpack.Configuration>;
11
+ export declare function getDevServerConfig(wco: WebpackConfigOptions<WebpackDevServerOptions>): Promise<Configuration>;
12
12
  /**
13
13
  * Resolve and build a URL _path_ that will be the root of the server. This resolved base href and
14
14
  * deploy URL from the browser options and returns a path from the root.
@@ -89,7 +89,7 @@ async function getDevServerConfig(wco) {
89
89
  },
90
90
  compress: false,
91
91
  static: false,
92
- https: getSslConfig(root, wco.buildOptions),
92
+ server: getServerConfig(root, wco.buildOptions),
93
93
  allowedHosts: getAllowedHostsConfig(wco.buildOptions),
94
94
  devMiddleware: {
95
95
  publicPath: servePath,
@@ -139,15 +139,20 @@ exports.buildServePath = buildServePath;
139
139
  * Private method to enhance a webpack config with SSL configuration.
140
140
  * @private
141
141
  */
142
- function getSslConfig(root, options) {
142
+ function getServerConfig(root, options) {
143
143
  const { ssl, sslCert, sslKey } = options;
144
- if (ssl && sslCert && sslKey) {
145
- return {
146
- key: (0, path_1.resolve)(root, sslKey),
147
- cert: (0, path_1.resolve)(root, sslCert),
148
- };
144
+ if (!ssl) {
145
+ return 'http';
149
146
  }
150
- return ssl;
147
+ return {
148
+ type: 'https',
149
+ options: sslCert && sslKey
150
+ ? {
151
+ key: (0, path_1.resolve)(root, sslKey),
152
+ cert: (0, path_1.resolve)(root, sslCert),
153
+ }
154
+ : undefined,
155
+ };
151
156
  }
152
157
  /**
153
158
  * Private method to enhance a webpack config with Proxy configuration.
@@ -158,21 +163,71 @@ async function addProxyConfig(root, proxyConfig) {
158
163
  return undefined;
159
164
  }
160
165
  const proxyPath = (0, path_1.resolve)(root, proxyConfig);
161
- if ((0, fs_1.existsSync)(proxyPath)) {
162
- try {
163
- return require(proxyPath);
166
+ if (!(0, fs_1.existsSync)(proxyPath)) {
167
+ throw new Error(`Proxy configuration file ${proxyPath} does not exist.`);
168
+ }
169
+ switch ((0, path_1.extname)(proxyPath)) {
170
+ case '.json': {
171
+ const content = await fs_1.promises.readFile(proxyPath, 'utf-8');
172
+ const { parse, printParseErrorCode } = await Promise.resolve().then(() => __importStar(require('jsonc-parser')));
173
+ const parseErrors = [];
174
+ const proxyConfiguration = parse(content, parseErrors, { allowTrailingComma: true });
175
+ if (parseErrors.length > 0) {
176
+ let errorMessage = `Proxy configuration file ${proxyPath} contains parse errors:`;
177
+ for (const parseError of parseErrors) {
178
+ const { line, column } = getJsonErrorLineColumn(parseError.offset, content);
179
+ errorMessage += `\n[${line}, ${column}] ${printParseErrorCode(parseError.error)}`;
180
+ }
181
+ throw new Error(errorMessage);
182
+ }
183
+ return proxyConfiguration;
164
184
  }
165
- catch (e) {
166
- if (e.code === 'ERR_REQUIRE_ESM') {
167
- // Load the ESM configuration file using the TypeScript dynamic import workaround.
168
- // Once TypeScript provides support for keeping the dynamic import this workaround can be
169
- // changed to a direct dynamic import.
170
- return (await (0, load_esm_1.loadEsmModule)(url.pathToFileURL(proxyPath))).default;
185
+ case '.mjs':
186
+ // Load the ESM configuration file using the TypeScript dynamic import workaround.
187
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
188
+ // changed to a direct dynamic import.
189
+ return (await (0, load_esm_1.loadEsmModule)(url.pathToFileURL(proxyPath))).default;
190
+ case '.cjs':
191
+ return require(proxyPath);
192
+ default:
193
+ // The file could be either CommonJS or ESM.
194
+ // CommonJS is tried first then ESM if loading fails.
195
+ try {
196
+ return require(proxyPath);
171
197
  }
172
- throw e;
198
+ catch (e) {
199
+ if (e.code === 'ERR_REQUIRE_ESM') {
200
+ // Load the ESM configuration file using the TypeScript dynamic import workaround.
201
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
202
+ // changed to a direct dynamic import.
203
+ return (await (0, load_esm_1.loadEsmModule)(url.pathToFileURL(proxyPath))).default;
204
+ }
205
+ throw e;
206
+ }
207
+ }
208
+ }
209
+ /**
210
+ * Calculates the line and column for an error offset in the content of a JSON file.
211
+ * @param location The offset error location from the beginning of the content.
212
+ * @param content The full content of the file containing the error.
213
+ * @returns An object containing the line and column
214
+ */
215
+ function getJsonErrorLineColumn(offset, content) {
216
+ if (offset === 0) {
217
+ return { line: 1, column: 1 };
218
+ }
219
+ let line = 0;
220
+ let position = 0;
221
+ // eslint-disable-next-line no-constant-condition
222
+ while (true) {
223
+ ++line;
224
+ const nextNewline = content.indexOf('\n', position);
225
+ if (nextNewline === -1 || nextNewline > offset) {
226
+ break;
173
227
  }
228
+ position = nextNewline + 1;
174
229
  }
175
- throw new Error('Proxy config file ' + proxyPath + ' does not exist.');
230
+ return { line, column: offset - position + 1 };
176
231
  }
177
232
  /**
178
233
  * Find the default server path. We don't want to expose baseHref and deployUrl as arguments, only
@@ -6,12 +6,6 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  export * from './analytics';
9
- export * from './browser';
10
9
  export * from './common';
11
10
  export * from './dev-server';
12
- export * from './server';
13
11
  export * from './styles';
14
- export * from './test';
15
- export * from './typescript';
16
- export * from './stats';
17
- export * from './worker';
@@ -18,12 +18,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  __exportStar(require("./analytics"), exports);
21
- __exportStar(require("./browser"), exports);
22
21
  __exportStar(require("./common"), exports);
23
22
  __exportStar(require("./dev-server"), exports);
24
- __exportStar(require("./server"), exports);
25
23
  __exportStar(require("./styles"), exports);
26
- __exportStar(require("./test"), exports);
27
- __exportStar(require("./typescript"), exports);
28
- __exportStar(require("./stats"), exports);
29
- __exportStar(require("./worker"), exports);
@@ -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 { Configuration } from 'webpack';
9
9
  import { WebpackConfigOptions } from '../../utils/build-options';
10
- export declare function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuration;
10
+ export declare function getStylesConfig(wco: WebpackConfigOptions): Configuration;
@@ -30,7 +30,6 @@ exports.getStylesConfig = void 0;
30
30
  const fs = __importStar(require("fs"));
31
31
  const path = __importStar(require("path"));
32
32
  const sass_service_1 = require("../../sass/sass-service");
33
- const build_browser_features_1 = require("../../utils/build-browser-features");
34
33
  const plugins_1 = require("../plugins");
35
34
  const css_optimizer_plugin_1 = require("../plugins/css-optimizer-plugin");
36
35
  const helpers_1 = require("../utils/helpers");
@@ -134,9 +133,8 @@ function getStylesConfig(wco) {
134
133
  extraPostcssPlugins.push(require(tailwindPackagePath)({ config: tailwindConfigPath }));
135
134
  }
136
135
  }
137
- const { supportedBrowsers } = new build_browser_features_1.BuildBrowserFeatures(wco.projectRoot);
138
136
  const postcssPresetEnvPlugin = postcssPresetEnv({
139
- browsers: supportedBrowsers,
137
+ browsers: buildOptions.supportedBrowsers,
140
138
  autoprefixer: true,
141
139
  stage: 3,
142
140
  });
@@ -361,7 +359,7 @@ function getStylesConfig(wco) {
361
359
  minimizer: buildOptions.optimization.styles.minify
362
360
  ? [
363
361
  new css_optimizer_plugin_1.CssOptimizerPlugin({
364
- supportedBrowsers,
362
+ supportedBrowsers: buildOptions.supportedBrowsers,
365
363
  }),
366
364
  ]
367
365
  : undefined,
@@ -11,4 +11,6 @@ export { SuppressExtractedTextChunksWebpackPlugin } from './suppress-entry-chunk
11
11
  export { RemoveHashPlugin, RemoveHashPluginOptions } from './remove-hash-plugin';
12
12
  export { DedupeModuleResolvePlugin } from './dedupe-module-resolve-plugin';
13
13
  export { CommonJsUsageWarnPlugin } from './common-js-usage-warn-plugin';
14
+ export { JsonStatsPlugin } from './json-stats-plugin';
15
+ export { JavaScriptOptimizerPlugin } from './javascript-optimizer-plugin';
14
16
  export { default as PostcssCliResources, PostcssCliResourcesOptions, } from './postcss-cli-resources';
@@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.PostcssCliResources = exports.CommonJsUsageWarnPlugin = exports.DedupeModuleResolvePlugin = exports.RemoveHashPlugin = exports.SuppressExtractedTextChunksWebpackPlugin = exports.ScriptsWebpackPlugin = exports.AnyComponentStyleBudgetChecker = void 0;
13
+ exports.PostcssCliResources = exports.JavaScriptOptimizerPlugin = exports.JsonStatsPlugin = exports.CommonJsUsageWarnPlugin = exports.DedupeModuleResolvePlugin = exports.RemoveHashPlugin = exports.SuppressExtractedTextChunksWebpackPlugin = exports.ScriptsWebpackPlugin = exports.AnyComponentStyleBudgetChecker = void 0;
14
14
  // Exports the webpack plugins we use internally.
15
15
  var any_component_style_budget_checker_1 = require("./any-component-style-budget-checker");
16
16
  Object.defineProperty(exports, "AnyComponentStyleBudgetChecker", { enumerable: true, get: function () { return any_component_style_budget_checker_1.AnyComponentStyleBudgetChecker; } });
@@ -24,5 +24,9 @@ var dedupe_module_resolve_plugin_1 = require("./dedupe-module-resolve-plugin");
24
24
  Object.defineProperty(exports, "DedupeModuleResolvePlugin", { enumerable: true, get: function () { return dedupe_module_resolve_plugin_1.DedupeModuleResolvePlugin; } });
25
25
  var common_js_usage_warn_plugin_1 = require("./common-js-usage-warn-plugin");
26
26
  Object.defineProperty(exports, "CommonJsUsageWarnPlugin", { enumerable: true, get: function () { return common_js_usage_warn_plugin_1.CommonJsUsageWarnPlugin; } });
27
+ var json_stats_plugin_1 = require("./json-stats-plugin");
28
+ Object.defineProperty(exports, "JsonStatsPlugin", { enumerable: true, get: function () { return json_stats_plugin_1.JsonStatsPlugin; } });
29
+ var javascript_optimizer_plugin_1 = require("./javascript-optimizer-plugin");
30
+ Object.defineProperty(exports, "JavaScriptOptimizerPlugin", { enumerable: true, get: function () { return javascript_optimizer_plugin_1.JavaScriptOptimizerPlugin; } });
27
31
  var postcss_cli_resources_1 = require("./postcss-cli-resources");
28
32
  Object.defineProperty(exports, "PostcssCliResources", { enumerable: true, get: function () { return __importDefault(postcss_cli_resources_1).default; } });
@@ -0,0 +1,13 @@
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 JsonStatsPlugin {
10
+ private readonly statsOutputPath;
11
+ constructor(statsOutputPath: string);
12
+ apply(compiler: Compiler): void;
13
+ }