@angular-devkit/build-angular 13.0.4 → 13.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +37 -37
- package/src/babel/presets/application.d.ts +1 -0
- package/src/babel/webpack-loader.js +9 -0
- package/src/builders/browser/index.js +7 -9
- package/src/builders/dev-server/index.js +31 -6
- package/src/builders/extract-i18n/index.js +1 -4
- package/src/builders/karma/index.d.ts +2 -2
- package/src/builders/karma/index.js +1 -7
- package/src/builders/server/index.js +1 -7
- package/src/utils/build-options.d.ts +1 -2
- package/src/utils/bundle-calculator.d.ts +6 -7
- package/src/utils/bundle-calculator.js +3 -1
- package/src/utils/i18n-inlining.js +18 -2
- package/src/utils/i18n-options.d.ts +16 -10
- package/src/utils/i18n-options.js +45 -34
- package/src/utils/index-file/augment-index-html.d.ts +5 -1
- package/src/utils/index-file/augment-index-html.js +25 -5
- package/src/utils/index.d.ts +0 -1
- package/src/utils/index.js +0 -1
- package/src/utils/normalize-builder-schema.js +2 -0
- package/src/{webpack/configs/worker.d.ts → utils/supported-browsers.d.ts} +1 -3
- package/src/utils/supported-browsers.js +26 -0
- package/src/webpack/configs/common.d.ts +2 -2
- package/src/webpack/configs/common.js +135 -158
- package/src/webpack/configs/dev-server.d.ts +2 -2
- package/src/webpack/configs/dev-server.js +74 -19
- package/src/webpack/configs/index.d.ts +0 -6
- package/src/webpack/configs/index.js +0 -6
- package/src/webpack/configs/styles.d.ts +2 -2
- package/src/webpack/configs/styles.js +2 -4
- package/src/webpack/plugins/index.d.ts +2 -0
- package/src/webpack/plugins/index.js +5 -1
- package/src/webpack/plugins/json-stats-plugin.d.ts +13 -0
- package/src/webpack/plugins/json-stats-plugin.js +54 -0
- package/src/webpack/plugins/named-chunks-plugin.d.ts +17 -0
- package/src/webpack/plugins/named-chunks-plugin.js +49 -0
- package/src/webpack/plugins/progress-plugin.d.ts +11 -0
- package/src/webpack/plugins/progress-plugin.js +38 -0
- package/src/webpack/plugins/transfer-size-plugin.d.ts +12 -0
- package/src/webpack/plugins/transfer-size-plugin.js +47 -0
- package/src/webpack/{configs/browser.d.ts → plugins/typescript.d.ts} +2 -2
- package/src/webpack/{configs → plugins}/typescript.js +5 -24
- package/src/webpack/utils/helpers.d.ts +15 -5
- package/src/webpack/utils/helpers.js +159 -34
- package/src/webpack/utils/stats.d.ts +10 -3
- package/src/webpack/utils/stats.js +112 -35
- package/src/utils/build-browser-features.d.ts +0 -16
- package/src/utils/build-browser-features.js +0 -54
- package/src/webpack/configs/browser.js +0 -81
- package/src/webpack/configs/server.d.ts +0 -14
- package/src/webpack/configs/server.js +0 -73
- package/src/webpack/configs/stats.d.ts +0 -38
- package/src/webpack/configs/stats.js +0 -53
- package/src/webpack/configs/test.d.ts +0 -10
- package/src/webpack/configs/test.js +0 -77
- package/src/webpack/configs/typescript.d.ts +0 -12
- package/src/webpack/configs/worker.js +0 -22
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.augmentIndexHtml = void 0;
|
|
11
11
|
const crypto_1 = require("crypto");
|
|
12
|
+
const load_esm_1 = require("../load-esm");
|
|
12
13
|
const html_rewriting_stream_1 = require("./html-rewriting-stream");
|
|
13
14
|
/*
|
|
14
15
|
* Helper function used by the IndexHtmlWebpackPlugin.
|
|
@@ -18,6 +19,8 @@ const html_rewriting_stream_1 = require("./html-rewriting-stream");
|
|
|
18
19
|
*/
|
|
19
20
|
async function augmentIndexHtml(params) {
|
|
20
21
|
const { loadOutputFile, files, entrypoints, sri, deployUrl = '', lang, baseHref, html } = params;
|
|
22
|
+
const warnings = [];
|
|
23
|
+
const errors = [];
|
|
21
24
|
let { crossOrigin = 'none' } = params;
|
|
22
25
|
if (sri && crossOrigin === 'none') {
|
|
23
26
|
crossOrigin = 'anonymous';
|
|
@@ -72,6 +75,7 @@ async function augmentIndexHtml(params) {
|
|
|
72
75
|
}
|
|
73
76
|
linkTags.push(`<link ${attrs.join(' ')}>`);
|
|
74
77
|
}
|
|
78
|
+
const dir = lang ? await getLanguageDirection(lang, warnings) : undefined;
|
|
75
79
|
const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
|
|
76
80
|
const baseTagExists = html.includes('<base');
|
|
77
81
|
rewriter
|
|
@@ -82,6 +86,9 @@ async function augmentIndexHtml(params) {
|
|
|
82
86
|
if (isString(lang)) {
|
|
83
87
|
updateAttribute(tag, 'lang', lang);
|
|
84
88
|
}
|
|
89
|
+
if (dir) {
|
|
90
|
+
updateAttribute(tag, 'dir', dir);
|
|
91
|
+
}
|
|
85
92
|
break;
|
|
86
93
|
case 'head':
|
|
87
94
|
// Base href should be added before any link, meta tags
|
|
@@ -119,11 +126,14 @@ async function augmentIndexHtml(params) {
|
|
|
119
126
|
rewriter.emitEndTag(tag);
|
|
120
127
|
});
|
|
121
128
|
const content = await transformedContent;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
return {
|
|
130
|
+
content: linkTags.length || scriptTags.length
|
|
131
|
+
? // In case no body/head tags are not present (dotnet partial templates)
|
|
132
|
+
linkTags.join('') + scriptTags.join('') + content
|
|
133
|
+
: content,
|
|
134
|
+
warnings,
|
|
135
|
+
errors,
|
|
136
|
+
};
|
|
127
137
|
}
|
|
128
138
|
exports.augmentIndexHtml = augmentIndexHtml;
|
|
129
139
|
function generateSriAttributes(content) {
|
|
@@ -144,3 +154,13 @@ function updateAttribute(tag, name, value) {
|
|
|
144
154
|
function isString(value) {
|
|
145
155
|
return typeof value === 'string';
|
|
146
156
|
}
|
|
157
|
+
async function getLanguageDirection(lang, warnings) {
|
|
158
|
+
try {
|
|
159
|
+
const localeData = (await (0, load_esm_1.loadEsmModule)(`@angular/common/locales/${lang}`)).default;
|
|
160
|
+
const dir = localeData[localeData.length - 2];
|
|
161
|
+
return isString(dir) ? dir : undefined;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
warnings.push(`Locale data for '${lang}' cannot be found. 'dir' attribute will not be set for this locale.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
package/src/utils/index.d.ts
CHANGED
|
@@ -5,7 +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
|
-
export * from './build-browser-features';
|
|
9
8
|
export * from './default-progress';
|
|
10
9
|
export * from './delete-output-dir';
|
|
11
10
|
export * from './run-module-as-observable-fork';
|
package/src/utils/index.js
CHANGED
|
@@ -17,7 +17,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./build-browser-features"), exports);
|
|
21
20
|
__exportStar(require("./default-progress"), exports);
|
|
22
21
|
__exportStar(require("./delete-output-dir"), exports);
|
|
23
22
|
__exportStar(require("./run-module-as-observable-fork"), exports);
|
|
@@ -14,6 +14,7 @@ const normalize_cache_1 = require("./normalize-cache");
|
|
|
14
14
|
const normalize_file_replacements_1 = require("./normalize-file-replacements");
|
|
15
15
|
const normalize_optimization_1 = require("./normalize-optimization");
|
|
16
16
|
const normalize_source_maps_1 = require("./normalize-source-maps");
|
|
17
|
+
const supported_browsers_1 = require("./supported-browsers");
|
|
17
18
|
function normalizeBrowserSchema(root, projectRoot, sourceRoot, options, metadata) {
|
|
18
19
|
const normalizedSourceMapOptions = (0, normalize_source_maps_1.normalizeSourceMaps)(options.sourceMap || false);
|
|
19
20
|
return {
|
|
@@ -37,6 +38,7 @@ function normalizeBrowserSchema(root, projectRoot, sourceRoot, options, metadata
|
|
|
37
38
|
// A value of 0 is falsy and will disable polling rather then enable
|
|
38
39
|
// 500 ms is a sensible default in this case
|
|
39
40
|
poll: options.poll === 0 ? 500 : options.poll,
|
|
41
|
+
supportedBrowsers: (0, supported_browsers_1.getSupportedBrowsers)((0, core_1.getSystemPath)(projectRoot)),
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
exports.normalizeBrowserSchema = normalizeBrowserSchema;
|
|
@@ -5,6 +5,4 @@
|
|
|
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
|
-
|
|
9
|
-
import { WebpackConfigOptions } from '../../utils/build-options';
|
|
10
|
-
export declare function getWorkerConfig(wco: WebpackConfigOptions): Configuration;
|
|
8
|
+
export declare function getSupportedBrowsers(projectRoot: string): string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.getSupportedBrowsers = void 0;
|
|
14
|
+
const browserslist_1 = __importDefault(require("browserslist"));
|
|
15
|
+
function getSupportedBrowsers(projectRoot) {
|
|
16
|
+
browserslist_1.default.defaults = [
|
|
17
|
+
'last 1 Chrome version',
|
|
18
|
+
'last 1 Firefox version',
|
|
19
|
+
'last 2 Edge major versions',
|
|
20
|
+
'last 2 Safari major versions',
|
|
21
|
+
'last 2 iOS major versions',
|
|
22
|
+
'Firefox ESR',
|
|
23
|
+
];
|
|
24
|
+
return (0, browserslist_1.default)(undefined, { path: projectRoot });
|
|
25
|
+
}
|
|
26
|
+
exports.getSupportedBrowsers = getSupportedBrowsers;
|
|
@@ -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
|
|
10
|
-
export declare function getCommonConfig(wco: WebpackConfigOptions
|
|
9
|
+
import { WebpackConfigOptions } from '../../utils/build-options';
|
|
10
|
+
export declare function getCommonConfig(wco: WebpackConfigOptions): Promise<Configuration>;
|
|
@@ -30,25 +30,26 @@ 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
|
|
39
|
-
const
|
|
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
|
|
42
|
+
const named_chunks_plugin_1 = require("../plugins/named-chunks-plugin");
|
|
43
|
+
const progress_plugin_1 = require("../plugins/progress-plugin");
|
|
44
|
+
const transfer_size_plugin_1 = require("../plugins/transfer-size-plugin");
|
|
45
|
+
const typescript_2 = require("../plugins/typescript");
|
|
46
46
|
const helpers_1 = require("../utils/helpers");
|
|
47
47
|
// eslint-disable-next-line max-lines-per-function
|
|
48
48
|
async function getCommonConfig(wco) {
|
|
49
49
|
var _a, _b;
|
|
50
|
-
const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot } = wco;
|
|
51
|
-
const { cache, codeCoverage,
|
|
50
|
+
const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot, tsConfigPath } = wco;
|
|
51
|
+
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;
|
|
52
|
+
const isPlatformServer = buildOptions.platform === 'server';
|
|
52
53
|
const extraPlugins = [];
|
|
53
54
|
const extraRules = [];
|
|
54
55
|
const entryPoints = {};
|
|
@@ -61,34 +62,18 @@ async function getCommonConfig(wco) {
|
|
|
61
62
|
const { GLOBAL_DEFS_FOR_TERSER, GLOBAL_DEFS_FOR_TERSER_WITH_AOT, VERSION: NG_VERSION, } = (compilerCliModule.GLOBAL_DEFS_FOR_TERSER ? compilerCliModule : compilerCliModule.default);
|
|
62
63
|
// determine hashing format
|
|
63
64
|
const hashFormat = (0, helpers_1.getOutputHashFormat)(buildOptions.outputHashing || 'none');
|
|
64
|
-
const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot);
|
|
65
65
|
if (buildOptions.progress) {
|
|
66
|
-
|
|
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 (
|
|
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
|
|
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
|
|
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 =
|
|
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:
|
|
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 (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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,48 @@ async function getCommonConfig(wco) {
|
|
|
251
188
|
},
|
|
252
189
|
});
|
|
253
190
|
}
|
|
191
|
+
if (main || polyfills) {
|
|
192
|
+
extraRules.push({
|
|
193
|
+
test: tsConfig.options.allowJs ? /\.[cm]?[tj]sx?$/ : /\.[cm]?tsx?$/,
|
|
194
|
+
loader: webpack_1.AngularWebpackLoaderPath,
|
|
195
|
+
// The below are known paths that are not part of the TypeScript compilation even when allowJs is enabled.
|
|
196
|
+
exclude: [/[/\\](?:css-loader|mini-css-extract-plugin|webpack-dev-server|webpack)[/\\]/],
|
|
197
|
+
});
|
|
198
|
+
extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, aot, tsConfigPath));
|
|
199
|
+
}
|
|
200
|
+
if (webWorkerTsConfig) {
|
|
201
|
+
extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, false, path.resolve(wco.root, webWorkerTsConfig)));
|
|
202
|
+
}
|
|
254
203
|
const extraMinimizers = [];
|
|
255
204
|
if (scriptsOptimization) {
|
|
256
|
-
extraMinimizers.push(new
|
|
205
|
+
extraMinimizers.push(new plugins_1.JavaScriptOptimizerPlugin({
|
|
257
206
|
define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
|
|
258
207
|
sourcemap: scriptsSourceMap,
|
|
259
208
|
target: wco.scriptTarget,
|
|
260
|
-
keepNames: !environment_options_1.allowMangle ||
|
|
209
|
+
keepNames: !environment_options_1.allowMangle || isPlatformServer,
|
|
261
210
|
removeLicenses: buildOptions.extractLicenses,
|
|
262
211
|
advanced: buildOptions.buildOptimizer,
|
|
263
212
|
}));
|
|
264
213
|
}
|
|
214
|
+
if (platform === 'browser' && (scriptsOptimization || stylesOptimization.minify)) {
|
|
215
|
+
extraMinimizers.push(new transfer_size_plugin_1.TransferSizePlugin());
|
|
216
|
+
}
|
|
217
|
+
const externals = [...externalDependencies];
|
|
218
|
+
if (isPlatformServer && !bundleDependencies) {
|
|
219
|
+
externals.push(({ context, request }, callback) => (0, helpers_1.externalizePackages)(context !== null && context !== void 0 ? context : wco.projectRoot, request, callback));
|
|
220
|
+
}
|
|
221
|
+
let crossOriginLoading = false;
|
|
222
|
+
if (subresourceIntegrity && crossOrigin === 'none') {
|
|
223
|
+
crossOriginLoading = 'anonymous';
|
|
224
|
+
}
|
|
225
|
+
else if (crossOrigin !== 'none') {
|
|
226
|
+
crossOriginLoading = crossOrigin;
|
|
227
|
+
}
|
|
265
228
|
return {
|
|
266
229
|
mode: scriptsOptimization || stylesOptimization.minify ? 'production' : 'development',
|
|
267
230
|
devtool: false,
|
|
268
231
|
target: [
|
|
269
|
-
|
|
232
|
+
isPlatformServer ? 'node' : 'web',
|
|
270
233
|
tsConfig.options.target === typescript_1.ScriptTarget.ES5 ? 'es5' : 'es2015',
|
|
271
234
|
],
|
|
272
235
|
profile: buildOptions.statsJson,
|
|
@@ -275,12 +238,17 @@ async function getCommonConfig(wco) {
|
|
|
275
238
|
extensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
276
239
|
symlinks: !buildOptions.preserveSymlinks,
|
|
277
240
|
modules: [tsConfig.options.baseUrl || projectRoot, 'node_modules'],
|
|
241
|
+
mainFields: isPlatformServer
|
|
242
|
+
? ['es2015', 'module', 'main']
|
|
243
|
+
: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
244
|
+
conditionNames: isPlatformServer ? ['es2015', '...'] : ['es2020', 'es2015', '...'],
|
|
278
245
|
},
|
|
279
246
|
resolveLoader: {
|
|
280
247
|
symlinks: !buildOptions.preserveSymlinks,
|
|
281
248
|
},
|
|
282
249
|
context: root,
|
|
283
250
|
entry: entryPoints,
|
|
251
|
+
externals,
|
|
284
252
|
output: {
|
|
285
253
|
uniqueName: projectName,
|
|
286
254
|
hashFunction: 'xxhash64',
|
|
@@ -289,9 +257,16 @@ async function getCommonConfig(wco) {
|
|
|
289
257
|
publicPath: (_b = buildOptions.deployUrl) !== null && _b !== void 0 ? _b : '',
|
|
290
258
|
filename: `[name]${hashFormat.chunk}.js`,
|
|
291
259
|
chunkFilename: `[name]${hashFormat.chunk}.js`,
|
|
260
|
+
libraryTarget: isPlatformServer ? 'commonjs' : undefined,
|
|
261
|
+
crossOriginLoading,
|
|
262
|
+
trustedTypes: 'angular#bundler',
|
|
263
|
+
scriptType: 'module',
|
|
292
264
|
},
|
|
293
265
|
watch: buildOptions.watch,
|
|
294
|
-
watchOptions:
|
|
266
|
+
watchOptions: {
|
|
267
|
+
poll,
|
|
268
|
+
ignored: poll === undefined ? undefined : '**/node_modules/**',
|
|
269
|
+
},
|
|
295
270
|
performance: {
|
|
296
271
|
hints: false,
|
|
297
272
|
},
|
|
@@ -307,6 +282,14 @@ async function getCommonConfig(wco) {
|
|
|
307
282
|
module: {
|
|
308
283
|
// Show an error for missing exports instead of a warning.
|
|
309
284
|
strictExportPresence: true,
|
|
285
|
+
parser: webWorkerTsConfig === undefined
|
|
286
|
+
? {
|
|
287
|
+
javascript: {
|
|
288
|
+
worker: false,
|
|
289
|
+
url: false,
|
|
290
|
+
},
|
|
291
|
+
}
|
|
292
|
+
: undefined,
|
|
310
293
|
rules: [
|
|
311
294
|
{
|
|
312
295
|
// Mark files inside `rxjs/add` as containing side effects.
|
|
@@ -342,54 +325,48 @@ async function getCommonConfig(wco) {
|
|
|
342
325
|
],
|
|
343
326
|
},
|
|
344
327
|
experiments: {
|
|
328
|
+
backCompat: false,
|
|
345
329
|
syncWebAssembly: true,
|
|
346
330
|
asyncWebAssembly: true,
|
|
347
331
|
},
|
|
348
332
|
infrastructureLogging: {
|
|
349
|
-
level:
|
|
333
|
+
level: verbose ? 'verbose' : 'error',
|
|
350
334
|
},
|
|
351
|
-
|
|
335
|
+
stats: (0, helpers_1.getStatsOptions)(verbose),
|
|
336
|
+
cache: (0, helpers_1.getCacheSettings)(wco, NG_VERSION.full),
|
|
352
337
|
optimization: {
|
|
353
338
|
minimizer: extraMinimizers,
|
|
354
339
|
moduleIds: 'deterministic',
|
|
355
340
|
chunkIds: buildOptions.namedChunks ? 'named' : 'deterministic',
|
|
356
341
|
emitOnErrors: false,
|
|
342
|
+
runtimeChunk: isPlatformServer ? false : 'single',
|
|
343
|
+
splitChunks: {
|
|
344
|
+
maxAsyncRequests: Infinity,
|
|
345
|
+
cacheGroups: {
|
|
346
|
+
default: !!commonChunk && {
|
|
347
|
+
chunks: 'async',
|
|
348
|
+
minChunks: 2,
|
|
349
|
+
priority: 10,
|
|
350
|
+
},
|
|
351
|
+
common: !!commonChunk && {
|
|
352
|
+
name: 'common',
|
|
353
|
+
chunks: 'async',
|
|
354
|
+
minChunks: 2,
|
|
355
|
+
enforce: true,
|
|
356
|
+
priority: 5,
|
|
357
|
+
},
|
|
358
|
+
vendors: false,
|
|
359
|
+
defaultVendors: !!vendorChunk && {
|
|
360
|
+
name: 'vendor',
|
|
361
|
+
chunks: (chunk) => chunk.name === 'main',
|
|
362
|
+
enforce: true,
|
|
363
|
+
test: /[\\/]node_modules[\\/]/,
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
},
|
|
357
367
|
},
|
|
358
|
-
plugins: [new plugins_1.DedupeModuleResolvePlugin({ verbose
|
|
368
|
+
plugins: [new named_chunks_plugin_1.NamedChunksPlugin(), new plugins_1.DedupeModuleResolvePlugin({ verbose }), ...extraPlugins],
|
|
369
|
+
node: false,
|
|
359
370
|
};
|
|
360
371
|
}
|
|
361
372
|
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
|
|
9
|
+
import { Configuration } from 'webpack';
|
|
10
10
|
import { WebpackConfigOptions, WebpackDevServerOptions } from '../../utils/build-options';
|
|
11
|
-
export declare function getDevServerConfig(wco: WebpackConfigOptions<WebpackDevServerOptions>): Promise<
|
|
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.
|