@angular-devkit/build-angular 13.0.0 → 13.1.0-next.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.
Files changed (35) hide show
  1. package/package.json +17 -17
  2. package/src/builders/browser/index.js +0 -4
  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 +0 -2
  9. package/src/utils/i18n-inlining.js +18 -2
  10. package/src/webpack/configs/common.d.ts +2 -2
  11. package/src/webpack/configs/common.js +127 -156
  12. package/src/webpack/configs/dev-server.d.ts +2 -2
  13. package/src/webpack/configs/index.d.ts +0 -6
  14. package/src/webpack/configs/index.js +0 -6
  15. package/src/webpack/configs/styles.d.ts +2 -2
  16. package/src/webpack/plugins/index.d.ts +2 -0
  17. package/src/webpack/plugins/index.js +5 -1
  18. package/src/webpack/plugins/json-stats-plugin.d.ts +13 -0
  19. package/src/webpack/plugins/json-stats-plugin.js +54 -0
  20. package/src/webpack/{configs/worker.d.ts → plugins/progress-plugin.d.ts} +4 -3
  21. package/src/webpack/plugins/progress-plugin.js +38 -0
  22. package/src/webpack/{configs/browser.d.ts → plugins/typescript.d.ts} +2 -2
  23. package/src/webpack/{configs → plugins}/typescript.js +5 -24
  24. package/src/webpack/utils/helpers.d.ts +15 -5
  25. package/src/webpack/utils/helpers.js +160 -34
  26. package/src/webpack/utils/stats.js +1 -2
  27. package/src/webpack/configs/browser.js +0 -81
  28. package/src/webpack/configs/server.d.ts +0 -14
  29. package/src/webpack/configs/server.js +0 -73
  30. package/src/webpack/configs/stats.d.ts +0 -38
  31. package/src/webpack/configs/stats.js +0 -53
  32. package/src/webpack/configs/test.d.ts +0 -10
  33. package/src/webpack/configs/test.js +0 -77
  34. package/src/webpack/configs/typescript.d.ts +0 -12
  35. package/src/webpack/configs/worker.js +0 -22
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "13.0.0",
3
+ "version": "13.1.0-next.0",
4
4
  "description": "Angular Webpack Build Facade",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
7
7
  "builders": "builders.json",
8
8
  "dependencies": {
9
9
  "@ampproject/remapping": "1.0.1",
10
- "@angular-devkit/architect": "0.1300.0",
11
- "@angular-devkit/build-webpack": "0.1300.0",
12
- "@angular-devkit/core": "13.0.0",
13
- "@babel/core": "7.15.8",
14
- "@babel/generator": "7.15.8",
15
- "@babel/helper-annotate-as-pure": "7.15.4",
16
- "@babel/plugin-proposal-async-generator-functions": "7.15.8",
17
- "@babel/plugin-transform-async-to-generator": "7.14.5",
18
- "@babel/plugin-transform-runtime": "7.15.8",
19
- "@babel/preset-env": "7.15.8",
20
- "@babel/runtime": "7.15.4",
21
- "@babel/template": "7.15.4",
10
+ "@angular-devkit/architect": "0.1301.0-next.0",
11
+ "@angular-devkit/build-webpack": "0.1301.0-next.0",
12
+ "@angular-devkit/core": "13.1.0-next.0",
13
+ "@babel/core": "7.16.0",
14
+ "@babel/generator": "7.16.0",
15
+ "@babel/helper-annotate-as-pure": "7.16.0",
16
+ "@babel/plugin-proposal-async-generator-functions": "7.16.0",
17
+ "@babel/plugin-transform-async-to-generator": "7.16.0",
18
+ "@babel/plugin-transform-runtime": "7.16.0",
19
+ "@babel/preset-env": "7.16.0",
20
+ "@babel/runtime": "7.16.0",
21
+ "@babel/template": "7.16.0",
22
22
  "@discoveryjs/json-ext": "0.5.5",
23
- "@ngtools/webpack": "13.0.0",
23
+ "@ngtools/webpack": "13.1.0-next.0",
24
24
  "ansi-colors": "4.1.1",
25
25
  "babel-loader": "8.2.3",
26
26
  "babel-plugin-istanbul": "6.1.1",
@@ -29,7 +29,7 @@
29
29
  "caniuse-lite": "^1.0.30001032",
30
30
  "circular-dependency-plugin": "5.2.2",
31
31
  "copy-webpack-plugin": "9.0.1",
32
- "core-js": "3.19.0",
32
+ "core-js": "3.19.1",
33
33
  "critters": "0.0.14",
34
34
  "css-loader": "6.5.0",
35
35
  "esbuild-wasm": "0.13.12",
@@ -40,7 +40,7 @@
40
40
  "less": "4.1.2",
41
41
  "less-loader": "10.2.0",
42
42
  "license-webpack-plugin": "3.0.0",
43
- "loader-utils": "3.0.0",
43
+ "loader-utils": "3.1.0",
44
44
  "mini-css-extract-plugin": "2.4.3",
45
45
  "minimatch": "3.0.4",
46
46
  "open": "8.4.0",
@@ -65,7 +65,7 @@
65
65
  "text-table": "0.2.0",
66
66
  "tree-kill": "1.2.2",
67
67
  "tslib": "2.3.1",
68
- "webpack": "5.60.0",
68
+ "webpack": "5.61.0",
69
69
  "webpack-dev-middleware": "5.2.1",
70
70
  "webpack-dev-server": "4.4.0",
71
71
  "webpack-merge": "5.8.0",
@@ -59,12 +59,8 @@ async function initialize(options, context, webpackConfigurationTransform) {
59
59
  const adjustedOptions = options.watch ? options : { ...options, assets: [] };
60
60
  const { config, projectRoot, projectSourceRoot, i18n, target } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)(adjustedOptions, context, (wco) => [
61
61
  (0, configs_1.getCommonConfig)(wco),
62
- (0, configs_1.getBrowserConfig)(wco),
63
62
  (0, configs_1.getStylesConfig)(wco),
64
- (0, configs_1.getStatsConfig)(wco),
65
63
  (0, configs_1.getAnalyticsConfig)(wco, context),
66
- (0, configs_1.getTypeScriptConfig)(wco),
67
- wco.buildOptions.webWorkerTsConfig ? (0, configs_1.getWorkerConfig)(wco) : {},
68
64
  ]);
69
65
  // Validate asset option values if processed directly
70
66
  if (((_a = options.assets) === null || _a === void 0 ? void 0 : _a.length) && !((_b = adjustedOptions.assets) === null || _b === void 0 ? void 0 : _b.length)) {
@@ -124,12 +124,8 @@ function serveWebpackBrowser(options, context, transforms = {}) {
124
124
  const { config, projectRoot, i18n } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)(browserOptions, context, (wco) => [
125
125
  (0, configs_1.getDevServerConfig)(wco),
126
126
  (0, configs_1.getCommonConfig)(wco),
127
- (0, configs_1.getBrowserConfig)(wco),
128
127
  (0, configs_1.getStylesConfig)(wco),
129
- (0, configs_1.getStatsConfig)(wco),
130
128
  (0, configs_1.getAnalyticsConfig)(wco, context),
131
- (0, configs_1.getTypeScriptConfig)(wco),
132
- browserOptions.webWorkerTsConfig ? (0, configs_1.getWorkerConfig)(wco) : {},
133
129
  ], options);
134
130
  if (!config.devServer) {
135
131
  throw new Error('Webpack Dev Server configuration was not set.');
@@ -166,6 +166,7 @@ async function execute(options, context, transforms) {
166
166
  subresourceIntegrity: false,
167
167
  outputHashing: schema_1.OutputHashing.None,
168
168
  namedChunks: true,
169
+ allowedCommonJsDependencies: undefined,
169
170
  };
170
171
  const { config, projectRoot } = await (0, webpack_browser_config_1.generateBrowserWebpackConfigFromContext)(builderOptions, context, (wco) => {
171
172
  var _a;
@@ -174,10 +175,6 @@ async function execute(options, context, transforms) {
174
175
  const partials = [
175
176
  { plugins: [new NoEmitPlugin()] },
176
177
  (0, configs_1.getCommonConfig)(wco),
177
- (0, configs_1.getBrowserConfig)(wco),
178
- (0, configs_1.getTypeScriptConfig)(wco),
179
- (0, configs_1.getWorkerConfig)(wco),
180
- (0, configs_1.getStatsConfig)(wco),
181
178
  ];
182
179
  // Add Ivy application file extractor support
183
180
  partials.unshift({
@@ -8,7 +8,7 @@
8
8
  import { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
9
9
  import { ConfigOptions } from 'karma';
10
10
  import { Observable } from 'rxjs';
11
- import * as webpack from 'webpack';
11
+ import { Configuration } from 'webpack';
12
12
  import { ExecutionTransformer } from '../../transforms';
13
13
  import { Schema as KarmaBuilderOptions } from './schema';
14
14
  export declare type KarmaConfigOptions = ConfigOptions & {
@@ -19,7 +19,7 @@ export declare type KarmaConfigOptions = ConfigOptions & {
19
19
  * @experimental Direct usage of this function is considered experimental.
20
20
  */
21
21
  export declare function execute(options: KarmaBuilderOptions, context: BuilderContext, transforms?: {
22
- webpackConfiguration?: ExecutionTransformer<webpack.Configuration>;
22
+ webpackConfiguration?: ExecutionTransformer<Configuration>;
23
23
  karmaOptions?: (options: KarmaConfigOptions) => KarmaConfigOptions;
24
24
  }): Observable<BuilderOutput>;
25
25
  export { KarmaBuilderOptions };
@@ -59,13 +59,7 @@ async function initialize(options, context, webpackConfigurationTransformer) {
59
59
  // https://github.com/webpack/webpack-dev-middleware/blob/698c9ae5e9bb9a013985add6189ff21c1a1ec185/src/index.js#L65
60
60
  // https://github.com/webpack/webpack/blob/cde1b73e12eb8a77eb9ba42e7920c9ec5d29c2c9/lib/Compiler.js#L379-L388
61
61
  watch: true,
62
- }, context, (wco) => [
63
- (0, configs_1.getCommonConfig)(wco),
64
- (0, configs_1.getStylesConfig)(wco),
65
- (0, configs_1.getTypeScriptConfig)(wco),
66
- (0, configs_1.getTestConfig)(wco),
67
- (0, configs_1.getWorkerConfig)(wco),
68
- ]);
62
+ }, context, (wco) => [(0, configs_1.getCommonConfig)(wco), (0, configs_1.getStylesConfig)(wco)]);
69
63
  const karma = await Promise.resolve().then(() => __importStar(require('karma')));
70
64
  return [
71
65
  karma,
@@ -109,13 +109,7 @@ async function initialize(options, context, webpackConfigurationTransform) {
109
109
  buildOptimizer: false,
110
110
  aot: true,
111
111
  platform: 'server',
112
- }, context, (wco) => [
113
- (0, configs_1.getCommonConfig)(wco),
114
- (0, configs_1.getServerConfig)(wco),
115
- (0, configs_1.getStylesConfig)(wco),
116
- (0, configs_1.getStatsConfig)(wco),
117
- (0, configs_1.getTypeScriptConfig)(wco),
118
- ]);
112
+ }, context, (wco) => [(0, configs_1.getCommonConfig)(wco), (0, configs_1.getStylesConfig)(wco)]);
119
113
  let transformedConfig;
120
114
  if (webpackConfigurationTransform) {
121
115
  transformedConfig = await webpackConfigurationTransform(config);
@@ -59,8 +59,6 @@ export interface BuildOptions {
59
59
  inlineStyleLanguage?: InlineStyleLanguage;
60
60
  allowedCommonJsDependencies?: string[];
61
61
  cache: NormalizedCachedOptions;
62
- }
63
- export interface WebpackTestOptions extends BuildOptions {
64
62
  codeCoverage?: boolean;
65
63
  codeCoverageExclude?: string[];
66
64
  }
@@ -32,7 +32,7 @@ const path = __importStar(require("path"));
32
32
  const action_executor_1 = require("./action-executor");
33
33
  const copy_assets_1 = require("./copy-assets");
34
34
  const spinner_1 = require("./spinner");
35
- function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath, es5, missingTranslation) {
35
+ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath, es5, missingTranslation, context) {
36
36
  const options = [];
37
37
  const originalFiles = [];
38
38
  for (const emittedFile of emittedFiles) {
@@ -51,16 +51,31 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
51
51
  setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
52
52
  };
53
53
  originalFiles.push(originalPath);
54
+ // Remove temporary original file as the content has now been read
55
+ try {
56
+ fs.unlinkSync(originalPath);
57
+ }
58
+ catch (e) {
59
+ context.logger.debug(`Unable to delete i18n temporary file [${originalPath}]: ${e.toString()}`);
60
+ }
54
61
  try {
55
62
  const originalMapPath = originalPath + '.map';
56
63
  action.map = fs.readFileSync(originalMapPath, 'utf8');
57
64
  originalFiles.push(originalMapPath);
65
+ // Remove temporary original map file as the content has now been read
66
+ try {
67
+ fs.unlinkSync(originalMapPath);
68
+ }
69
+ catch (e) {
70
+ context.logger.debug(`Unable to delete i18n temporary file [${originalMapPath}]: ${e.toString()}`);
71
+ }
58
72
  }
59
73
  catch (err) {
60
74
  if (err.code !== 'ENOENT') {
61
75
  throw err;
62
76
  }
63
77
  }
78
+ context.logger.debug(`i18n file queued for processing: ${action.filename}`);
64
79
  options.push(action);
65
80
  }
66
81
  return { options, originalFiles };
@@ -71,8 +86,9 @@ async function i18nInlineEmittedFiles(context, emittedFiles, i18n, baseOutputPat
71
86
  const spinner = new spinner_1.Spinner();
72
87
  spinner.start('Generating localized bundles...');
73
88
  try {
74
- const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath, es5, missingTranslation);
89
+ const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath, es5, missingTranslation, context);
75
90
  for await (const result of executor.inlineAll(options)) {
91
+ context.logger.debug(`i18n file processed: ${result.file}`);
76
92
  for (const diagnostic of result.diagnostics) {
77
93
  spinner.stop();
78
94
  if (diagnostic.type === 'error') {
@@ -6,5 +6,5 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { Configuration } from 'webpack';
9
- import { WebpackConfigOptions, WebpackTestOptions } from '../../utils/build-options';
10
- export declare function getCommonConfig(wco: WebpackConfigOptions<WebpackTestOptions>): Promise<Configuration>;
9
+ import { WebpackConfigOptions } from '../../utils/build-options';
10
+ export declare function getCommonConfig(wco: WebpackConfigOptions): Promise<Configuration>;
@@ -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");
37
+ const webpack_2 = require("webpack");
38
+ const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
39
39
  const utils_1 = require("../../utils");
40
40
  const environment_options_1 = require("../../utils/environment-options");
41
41
  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
42
  const plugins_1 = require("../plugins");
45
- const javascript_optimizer_plugin_1 = require("../plugins/javascript-optimizer-plugin");
43
+ const progress_plugin_1 = require("../plugins/progress-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 = {};
@@ -63,32 +63,17 @@ async function getCommonConfig(wco) {
63
63
  const hashFormat = (0, helpers_1.getOutputHashFormat)(buildOptions.outputHashing || 'none');
64
64
  const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot);
65
65
  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
- }));
66
+ extraPlugins.push(new progress_plugin_1.ProgressPlugin(platform));
86
67
  }
87
68
  if (buildOptions.main) {
88
69
  const mainPath = path.resolve(root, buildOptions.main);
89
70
  entryPoints['main'] = [mainPath];
90
71
  }
91
- if (platform !== 'server') {
72
+ if (isPlatformServer) {
73
+ // Fixes Critical dependency: the request of a dependency is an expression
74
+ extraPlugins.push(new webpack_2.ContextReplacementPlugin(/@?hapi|express[\\/]/));
75
+ }
76
+ if (!isPlatformServer) {
92
77
  if (buildOptions.polyfills) {
93
78
  const projectPolyfills = path.resolve(root, buildOptions.polyfills);
94
79
  if (entryPoints['polyfills']) {
@@ -109,89 +94,34 @@ async function getCommonConfig(wco) {
109
94
  }
110
95
  }
111
96
  if (environment_options_1.profilingEnabled) {
112
- extraPlugins.push(new webpack_1.debug.ProfilingPlugin({
97
+ extraPlugins.push(new webpack_2.debug.ProfilingPlugin({
113
98
  outputPath: path.resolve(root, 'chrome-profiler-events.json'),
114
99
  }));
115
100
  }
101
+ if (allowedCommonJsDependencies) {
102
+ // When this is not defined it means the builder doesn't support showing common js usages.
103
+ // When it does it will be an array.
104
+ extraPlugins.push(new plugins_1.CommonJsUsageWarnPlugin({
105
+ allowedDependencies: allowedCommonJsDependencies,
106
+ }));
107
+ }
116
108
  // 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
109
  // Add a new asset for each entry.
146
- for (const script of globalScriptsByBundleName) {
110
+ for (const { bundleName, inject, paths } of (0, helpers_1.globalScriptsByBundleName)(root, buildOptions.scripts)) {
147
111
  // 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;
112
+ const hash = inject ? hashFormat.script : '';
150
113
  extraPlugins.push(new plugins_1.ScriptsWebpackPlugin({
151
114
  name: bundleName,
152
115
  sourceMap: scriptsSourceMap,
116
+ scripts: paths,
153
117
  filename: `${path.basename(bundleName)}${hash}.js`,
154
- scripts: script.paths,
155
118
  basePath: projectRoot,
156
119
  }));
157
120
  }
158
121
  // process asset entries
159
122
  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
123
  extraPlugins.push(new copy_webpack_plugin_1.default({
194
- patterns: copyWebpackPluginPatterns,
124
+ patterns: (0, helpers_1.assetPatterns)(root, buildOptions.assets),
195
125
  }));
196
126
  }
197
127
  if (buildOptions.showCircularDependencies) {
@@ -212,26 +142,33 @@ async function getCommonConfig(wco) {
212
142
  skipChildCompilers: true,
213
143
  }));
214
144
  }
145
+ if (scriptsSourceMap || stylesSourceMap) {
146
+ const include = [];
147
+ if (scriptsSourceMap) {
148
+ include.push(/js$/);
149
+ }
150
+ if (stylesSourceMap) {
151
+ include.push(/css$/);
152
+ }
153
+ extraPlugins.push(new webpack_2.SourceMapDevToolPlugin({
154
+ filename: '[file].map',
155
+ include,
156
+ // We want to set sourceRoot to `webpack:///` for non
157
+ // inline sourcemaps as otherwise paths to sourcemaps will be broken in browser
158
+ // `webpack:///` is needed for Visual Studio breakpoints to work properly as currently
159
+ // there is no way to set the 'webRoot'
160
+ sourceRoot: 'webpack:///',
161
+ moduleFilenameTemplate: '[resource-path]',
162
+ append: hiddenSourceMap ? false : undefined,
163
+ }));
164
+ }
215
165
  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
- })());
166
+ extraPlugins.push(new plugins_1.JsonStatsPlugin(path.resolve(root, buildOptions.outputPath, 'stats.json')));
167
+ }
168
+ if (subresourceIntegrity) {
169
+ extraPlugins.push(new webpack_subresource_integrity_1.SubresourceIntegrityPlugin({
170
+ hashFuncNames: ['sha384'],
171
+ }));
235
172
  }
236
173
  if (scriptsSourceMap || stylesSourceMap) {
237
174
  extraRules.push({
@@ -251,22 +188,43 @@ async function getCommonConfig(wco) {
251
188
  },
252
189
  });
253
190
  }
191
+ if (main || polyfills) {
192
+ extraRules.push({
193
+ test: /\.[cm]?[tj]sx?$/,
194
+ loader: webpack_1.AngularWebpackLoaderPath,
195
+ });
196
+ extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, aot, tsConfigPath));
197
+ }
198
+ if (webWorkerTsConfig) {
199
+ extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, false, path.resolve(wco.root, webWorkerTsConfig)));
200
+ }
254
201
  const extraMinimizers = [];
255
202
  if (scriptsOptimization) {
256
- extraMinimizers.push(new javascript_optimizer_plugin_1.JavaScriptOptimizerPlugin({
203
+ extraMinimizers.push(new plugins_1.JavaScriptOptimizerPlugin({
257
204
  define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
258
205
  sourcemap: scriptsSourceMap,
259
206
  target: wco.scriptTarget,
260
- keepNames: !environment_options_1.allowMangle || platform === 'server',
207
+ keepNames: !environment_options_1.allowMangle || isPlatformServer,
261
208
  removeLicenses: buildOptions.extractLicenses,
262
209
  advanced: buildOptions.buildOptimizer,
263
210
  }));
264
211
  }
212
+ const externals = [...externalDependencies];
213
+ if (isPlatformServer && !bundleDependencies) {
214
+ externals.push(({ context, request }, callback) => (0, helpers_1.externalizePackages)(context !== null && context !== void 0 ? context : wco.projectRoot, request, callback));
215
+ }
216
+ let crossOriginLoading = false;
217
+ if (subresourceIntegrity && crossOrigin === 'none') {
218
+ crossOriginLoading = 'anonymous';
219
+ }
220
+ else if (crossOrigin !== 'none') {
221
+ crossOriginLoading = crossOrigin;
222
+ }
265
223
  return {
266
224
  mode: scriptsOptimization || stylesOptimization.minify ? 'production' : 'development',
267
225
  devtool: false,
268
226
  target: [
269
- platform === 'server' ? 'node' : 'web',
227
+ isPlatformServer ? 'node' : 'web',
270
228
  tsConfig.options.target === typescript_1.ScriptTarget.ES5 ? 'es5' : 'es2015',
271
229
  ],
272
230
  profile: buildOptions.statsJson,
@@ -275,12 +233,17 @@ async function getCommonConfig(wco) {
275
233
  extensions: ['.ts', '.tsx', '.mjs', '.js'],
276
234
  symlinks: !buildOptions.preserveSymlinks,
277
235
  modules: [tsConfig.options.baseUrl || projectRoot, 'node_modules'],
236
+ mainFields: isPlatformServer
237
+ ? ['es2015', 'module', 'main']
238
+ : ['es2020', 'es2015', 'browser', 'module', 'main'],
239
+ conditionNames: isPlatformServer ? ['es2015', '...'] : ['es2020', 'es2015', '...'],
278
240
  },
279
241
  resolveLoader: {
280
242
  symlinks: !buildOptions.preserveSymlinks,
281
243
  },
282
244
  context: root,
283
245
  entry: entryPoints,
246
+ externals,
284
247
  output: {
285
248
  uniqueName: projectName,
286
249
  hashFunction: 'xxhash64',
@@ -289,9 +252,16 @@ async function getCommonConfig(wco) {
289
252
  publicPath: (_b = buildOptions.deployUrl) !== null && _b !== void 0 ? _b : '',
290
253
  filename: `[name]${hashFormat.chunk}.js`,
291
254
  chunkFilename: `[name]${hashFormat.chunk}.js`,
255
+ libraryTarget: isPlatformServer ? 'commonjs' : undefined,
256
+ crossOriginLoading,
257
+ trustedTypes: 'angular#bundler',
258
+ scriptType: 'module',
292
259
  },
293
260
  watch: buildOptions.watch,
294
- watchOptions: (0, helpers_1.getWatchOptions)(buildOptions.poll),
261
+ watchOptions: {
262
+ poll,
263
+ ignored: poll === undefined ? undefined : 'node_modules/**',
264
+ },
295
265
  performance: {
296
266
  hints: false,
297
267
  },
@@ -304,6 +274,14 @@ async function getCommonConfig(wco) {
304
274
  module: {
305
275
  // Show an error for missing exports instead of a warning.
306
276
  strictExportPresence: true,
277
+ parser: webWorkerTsConfig === undefined
278
+ ? {
279
+ javascript: {
280
+ worker: false,
281
+ url: false,
282
+ },
283
+ }
284
+ : undefined,
307
285
  rules: [
308
286
  {
309
287
  // Mark files inside `rxjs/add` as containing side effects.
@@ -343,50 +321,43 @@ async function getCommonConfig(wco) {
343
321
  asyncWebAssembly: true,
344
322
  },
345
323
  infrastructureLogging: {
346
- level: buildOptions.verbose ? 'verbose' : 'error',
324
+ level: verbose ? 'verbose' : 'error',
347
325
  },
348
- cache: getCacheSettings(wco, buildBrowserFeatures.supportedBrowsers, NG_VERSION.full),
326
+ stats: (0, helpers_1.getStatsOptions)(verbose),
327
+ cache: (0, helpers_1.getCacheSettings)(wco, buildBrowserFeatures.supportedBrowsers, NG_VERSION.full),
349
328
  optimization: {
350
329
  minimizer: extraMinimizers,
351
330
  moduleIds: 'deterministic',
352
331
  chunkIds: buildOptions.namedChunks ? 'named' : 'deterministic',
353
332
  emitOnErrors: false,
333
+ runtimeChunk: isPlatformServer ? false : 'single',
334
+ splitChunks: {
335
+ maxAsyncRequests: Infinity,
336
+ cacheGroups: {
337
+ default: !!commonChunk && {
338
+ chunks: 'async',
339
+ minChunks: 2,
340
+ priority: 10,
341
+ },
342
+ common: !!commonChunk && {
343
+ name: 'common',
344
+ chunks: 'async',
345
+ minChunks: 2,
346
+ enforce: true,
347
+ priority: 5,
348
+ },
349
+ vendors: false,
350
+ defaultVendors: !!vendorChunk && {
351
+ name: 'vendor',
352
+ chunks: (chunk) => chunk.name === 'main',
353
+ enforce: true,
354
+ test: /[\\/]node_modules[\\/]/,
355
+ },
356
+ },
357
+ },
354
358
  },
355
- plugins: [new plugins_1.DedupeModuleResolvePlugin({ verbose: buildOptions.verbose }), ...extraPlugins],
359
+ plugins: [new plugins_1.DedupeModuleResolvePlugin({ verbose }), ...extraPlugins],
360
+ node: false,
356
361
  };
357
362
  }
358
363
  exports.getCommonConfig = getCommonConfig;
359
- function getCacheSettings(wco, supportedBrowsers, angularVersion) {
360
- const { enabled, path: cacheDirectory } = wco.buildOptions.cache;
361
- if (enabled) {
362
- const packageVersion = require('../../../package.json').version;
363
- return {
364
- type: 'filesystem',
365
- cacheDirectory: path.join(cacheDirectory, 'angular-webpack'),
366
- maxMemoryGenerations: 1,
367
- // We use the versions and build options as the cache name. The Webpack configurations are too
368
- // dynamic and shared among different build types: test, build and serve.
369
- // None of which are "named".
370
- name: (0, crypto_1.createHash)('sha1')
371
- .update(angularVersion)
372
- .update(packageVersion)
373
- .update(wco.projectRoot)
374
- .update(JSON.stringify(wco.tsConfig))
375
- .update(JSON.stringify({
376
- ...wco.buildOptions,
377
- // Needed because outputPath changes on every build when using i18n extraction
378
- // https://github.com/angular/angular-cli/blob/736a5f89deaca85f487b78aec9ff66d4118ceb6a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts#L264-L265
379
- outputPath: undefined,
380
- }))
381
- .update(supportedBrowsers.join(''))
382
- .digest('hex'),
383
- };
384
- }
385
- if (wco.buildOptions.watch) {
386
- return {
387
- type: 'memory',
388
- maxGenerations: 1,
389
- };
390
- }
391
- return false;
392
- }
@@ -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.