@angular-devkit/build-angular 13.2.0-next.0 → 13.2.0-rc.1
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/webpack-loader.js +2 -1
- package/src/builders/browser/index.d.ts +5 -0
- package/src/builders/browser/index.js +9 -1
- package/src/builders/browser/schema.d.ts +8 -2
- package/src/builders/browser/schema.js +9 -7
- package/src/builders/browser/schema.json +6 -0
- package/src/builders/dev-server/index.js +8 -3
- package/src/builders/extract-i18n/index.js +3 -0
- package/src/builders/karma/index.js +3 -0
- package/src/builders/ng-packagr/index.js +3 -0
- package/src/builders/server/index.js +3 -0
- package/src/builders/server/schema.d.ts +8 -2
- package/src/builders/server/schema.js +9 -7
- package/src/builders/server/schema.json +6 -0
- package/src/sass/sass-service.d.ts +3 -3
- package/src/utils/build-options.d.ts +2 -2
- package/src/utils/i18n-inlining.js +0 -14
- package/src/utils/i18n-options.d.ts +2 -2
- package/src/utils/i18n-options.js +40 -13
- package/src/utils/index-file/inline-fonts.js +2 -2
- package/src/utils/normalize-cache.d.ts +4 -0
- package/src/utils/normalize-cache.js +4 -1
- package/src/utils/package-version.d.ts +8 -0
- package/src/utils/package-version.js +11 -0
- package/src/utils/purge-cache.d.ts +10 -0
- package/src/utils/purge-cache.js +41 -0
- package/src/webpack/configs/common.js +11 -10
- package/src/webpack/configs/dev-server.js +26 -14
- package/src/webpack/configs/styles.js +12 -12
- package/src/webpack/plugins/any-component-style-budget-checker.js +4 -0
- package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +14 -6
- package/src/webpack/plugins/javascript-optimizer-plugin.js +5 -4
- package/src/webpack/plugins/javascript-optimizer-worker.d.ts +45 -37
- package/src/webpack/plugins/javascript-optimizer-worker.js +10 -2
- package/src/webpack/plugins/karma/karma.js +2 -2
- package/src/webpack/utils/helpers.js +5 -4
|
@@ -16,6 +16,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
16
16
|
const module_1 = __importDefault(require("module"));
|
|
17
17
|
const os_1 = __importDefault(require("os"));
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const schema_1 = require("../builders/browser/schema");
|
|
19
20
|
const read_tsconfig_1 = require("../utils/read-tsconfig");
|
|
20
21
|
const load_translations_1 = require("./load-translations");
|
|
21
22
|
/**
|
|
@@ -166,7 +167,7 @@ async function configureI18nBuild(context, options) {
|
|
|
166
167
|
error(message) {
|
|
167
168
|
throw new Error(message);
|
|
168
169
|
},
|
|
169
|
-
}, usedFormats);
|
|
170
|
+
}, usedFormats, buildOptions.i18nDuplicateTranslation);
|
|
170
171
|
if (usedFormats.size > 1 && tsConfig.options.enableI18nLegacyMessageIdFormat !== false) {
|
|
171
172
|
// This limitation is only for legacy message id support (defaults to true as of 9.0)
|
|
172
173
|
throw new Error('Localization currently only supports using one type of translation file format for the entire application.');
|
|
@@ -176,12 +177,11 @@ async function configureI18nBuild(context, options) {
|
|
|
176
177
|
if (i18n.shouldInline) {
|
|
177
178
|
const tempPath = fs_1.default.mkdtempSync(path_1.default.join(fs_1.default.realpathSync(os_1.default.tmpdir()), 'angular-cli-i18n-'));
|
|
178
179
|
buildOptions.outputPath = tempPath;
|
|
179
|
-
|
|
180
|
-
process.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
catch { }
|
|
180
|
+
process.on('exit', () => deleteTempDirectory(tempPath));
|
|
181
|
+
process.once('SIGINT', () => {
|
|
182
|
+
deleteTempDirectory(tempPath);
|
|
183
|
+
// Needed due to `ora` as otherwise process will not terminate.
|
|
184
|
+
process.kill(process.pid, 'SIGINT');
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
return { buildOptions, i18n };
|
|
@@ -201,7 +201,22 @@ function findLocaleDataPath(locale, resolver) {
|
|
|
201
201
|
return null;
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
|
|
204
|
+
/** Remove temporary directory used for i18n processing. */
|
|
205
|
+
function deleteTempDirectory(tempPath) {
|
|
206
|
+
// The below should be removed and replaced with just `rmSync` when support for Node.Js 12 is removed.
|
|
207
|
+
const { rmSync, rmdirSync } = fs_1.default;
|
|
208
|
+
try {
|
|
209
|
+
if (rmSync) {
|
|
210
|
+
rmSync(tempPath, { force: true, recursive: true, maxRetries: 3 });
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
rmdirSync(tempPath, { recursive: true, maxRetries: 3 });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch { }
|
|
217
|
+
}
|
|
218
|
+
function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats, duplicateTranslation) {
|
|
219
|
+
let translations = undefined;
|
|
205
220
|
for (const file of desc.files) {
|
|
206
221
|
const loadResult = loader(path_1.default.join(workspaceRoot, file.path));
|
|
207
222
|
for (const diagnostics of loadResult.diagnostics.messages) {
|
|
@@ -218,19 +233,31 @@ function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedForma
|
|
|
218
233
|
usedFormats === null || usedFormats === void 0 ? void 0 : usedFormats.add(loadResult.format);
|
|
219
234
|
file.format = loadResult.format;
|
|
220
235
|
file.integrity = loadResult.integrity;
|
|
221
|
-
if (
|
|
236
|
+
if (translations) {
|
|
222
237
|
// Merge translations
|
|
223
238
|
for (const [id, message] of Object.entries(loadResult.translations)) {
|
|
224
|
-
if (
|
|
225
|
-
|
|
239
|
+
if (translations[id] !== undefined) {
|
|
240
|
+
const duplicateTranslationMessage = `[${file.path}]: Duplicate translations for message '${id}' when merging.`;
|
|
241
|
+
switch (duplicateTranslation) {
|
|
242
|
+
case schema_1.I18NTranslation.Ignore:
|
|
243
|
+
break;
|
|
244
|
+
case schema_1.I18NTranslation.Error:
|
|
245
|
+
logger.error(`ERROR ${duplicateTranslationMessage}`);
|
|
246
|
+
break;
|
|
247
|
+
case schema_1.I18NTranslation.Warning:
|
|
248
|
+
default:
|
|
249
|
+
logger.warn(`WARNING ${duplicateTranslationMessage}`);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
226
252
|
}
|
|
227
|
-
|
|
253
|
+
translations[id] = message;
|
|
228
254
|
}
|
|
229
255
|
}
|
|
230
256
|
else {
|
|
231
257
|
// First or only translation file
|
|
232
|
-
|
|
258
|
+
translations = loadResult.translations;
|
|
233
259
|
}
|
|
234
260
|
}
|
|
261
|
+
desc.translation = translations;
|
|
235
262
|
}
|
|
236
263
|
exports.loadTranslations = loadTranslations;
|
|
@@ -36,8 +36,8 @@ const https = __importStar(require("https"));
|
|
|
36
36
|
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
|
|
37
37
|
const path_1 = require("path");
|
|
38
38
|
const url_1 = require("url");
|
|
39
|
+
const package_version_1 = require("../package-version");
|
|
39
40
|
const html_rewriting_stream_1 = require("./html-rewriting-stream");
|
|
40
|
-
const packageVersion = require('../../../package.json').version;
|
|
41
41
|
const SUPPORTED_PROVIDERS = {
|
|
42
42
|
'fonts.googleapis.com': {
|
|
43
43
|
preconnectUrl: 'https://fonts.gstatic.com',
|
|
@@ -146,7 +146,7 @@ class InlineFontsProcessor {
|
|
|
146
146
|
}
|
|
147
147
|
async getResponse(url) {
|
|
148
148
|
var _a;
|
|
149
|
-
const key = `${
|
|
149
|
+
const key = `${package_version_1.VERSION}|${url}`;
|
|
150
150
|
if (this.cachePath) {
|
|
151
151
|
const entry = await cacache.get.info(this.cachePath, key);
|
|
152
152
|
if (entry) {
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { json } from '@angular-devkit/core';
|
|
9
9
|
export interface NormalizedCachedOptions {
|
|
10
|
+
/** Whether disk cache is enabled. */
|
|
10
11
|
enabled: boolean;
|
|
12
|
+
/** Disk cache path. Example: `/.angular/cache/v12.0.0`. */
|
|
11
13
|
path: string;
|
|
14
|
+
/** Disk cache base path. Example: `/.angular/cache`. */
|
|
15
|
+
basePath: string;
|
|
12
16
|
}
|
|
13
17
|
export declare function normalizeCacheOptions(metadata: json.JsonObject, worspaceRoot: string): NormalizedCachedOptions;
|
|
@@ -11,6 +11,7 @@ exports.normalizeCacheOptions = void 0;
|
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const environment_options_1 = require("./environment-options");
|
|
14
|
+
const package_version_1 = require("./package-version");
|
|
14
15
|
function normalizeCacheOptions(metadata, worspaceRoot) {
|
|
15
16
|
var _a;
|
|
16
17
|
const cacheMetadata = core_1.json.isJsonObject(metadata.cli) && core_1.json.isJsonObject(metadata.cli.cache)
|
|
@@ -32,9 +33,11 @@ function normalizeCacheOptions(metadata, worspaceRoot) {
|
|
|
32
33
|
break;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
const cacheBasePath = (0, path_1.resolve)(worspaceRoot, path);
|
|
35
37
|
return {
|
|
36
38
|
enabled: cacheEnabled,
|
|
37
|
-
|
|
39
|
+
basePath: cacheBasePath,
|
|
40
|
+
path: (0, path_1.join)(cacheBasePath, package_version_1.VERSION),
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
exports.normalizeCacheOptions = normalizeCacheOptions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.VERSION = void 0;
|
|
11
|
+
exports.VERSION = require('../../package.json').version;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 { BuilderContext } from '@angular-devkit/architect';
|
|
9
|
+
/** Delete stale cache directories used by previous versions of build-angular. */
|
|
10
|
+
export declare function purgeStaleBuildCache(context: BuilderContext): Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.purgeStaleBuildCache = void 0;
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const normalize_cache_1 = require("./normalize-cache");
|
|
14
|
+
/** Delete stale cache directories used by previous versions of build-angular. */
|
|
15
|
+
async function purgeStaleBuildCache(context) {
|
|
16
|
+
var _a;
|
|
17
|
+
const projectName = (_a = context.target) === null || _a === void 0 ? void 0 : _a.project;
|
|
18
|
+
if (!projectName) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const metadata = await context.getProjectMetadata(projectName);
|
|
22
|
+
const { basePath, path, enabled } = (0, normalize_cache_1.normalizeCacheOptions)(metadata, context.workspaceRoot);
|
|
23
|
+
if (!enabled || !(0, fs_1.existsSync)(basePath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// The below should be removed and replaced with just `rm` when support for Node.Js 12 is removed.
|
|
27
|
+
const { rm, rmdir } = fs_1.promises;
|
|
28
|
+
const entriesToDelete = (await fs_1.promises.readdir(basePath, { withFileTypes: true }))
|
|
29
|
+
.filter((d) => (0, path_1.join)(basePath, d.name) !== path && d.isDirectory())
|
|
30
|
+
.map((d) => {
|
|
31
|
+
const subPath = (0, path_1.join)(basePath, d.name);
|
|
32
|
+
try {
|
|
33
|
+
return rm
|
|
34
|
+
? rm(subPath, { force: true, recursive: true, maxRetries: 3 })
|
|
35
|
+
: rmdir(subPath, { recursive: true, maxRetries: 3 });
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
});
|
|
39
|
+
await Promise.all(entriesToDelete);
|
|
40
|
+
}
|
|
41
|
+
exports.purgeStaleBuildCache = purgeStaleBuildCache;
|
|
@@ -81,7 +81,7 @@ async function getCommonConfig(wco) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
if (!buildOptions.aot) {
|
|
84
|
-
const jitPolyfills = 'core-js/proposals/reflect-metadata';
|
|
84
|
+
const jitPolyfills = require.resolve('core-js/proposals/reflect-metadata');
|
|
85
85
|
if (entryPoints['polyfills']) {
|
|
86
86
|
entryPoints['polyfills'].push(jitPolyfills);
|
|
87
87
|
}
|
|
@@ -198,7 +198,8 @@ async function getCommonConfig(wco) {
|
|
|
198
198
|
define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
|
|
199
199
|
sourcemap: scriptsSourceMap,
|
|
200
200
|
target: scriptTarget,
|
|
201
|
-
|
|
201
|
+
keepIdentifierNames: !environment_options_1.allowMangle || isPlatformServer,
|
|
202
|
+
keepNames: isPlatformServer,
|
|
202
203
|
removeLicenses: buildOptions.extractLicenses,
|
|
203
204
|
advanced: buildOptions.buildOptimizer,
|
|
204
205
|
}));
|
|
@@ -271,14 +272,14 @@ async function getCommonConfig(wco) {
|
|
|
271
272
|
module: {
|
|
272
273
|
// Show an error for missing exports instead of a warning.
|
|
273
274
|
strictExportPresence: true,
|
|
274
|
-
parser:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
275
|
+
parser: {
|
|
276
|
+
javascript: {
|
|
277
|
+
// Disable auto URL asset module creation. This doesn't effect `new Worker(new URL(...))`
|
|
278
|
+
// https://webpack.js.org/guides/asset-modules/#url-assets
|
|
279
|
+
url: false,
|
|
280
|
+
worker: !!webWorkerTsConfig,
|
|
281
|
+
},
|
|
282
|
+
},
|
|
282
283
|
rules: [
|
|
283
284
|
{
|
|
284
285
|
test: /\.?(svg|html)$/,
|
|
@@ -58,7 +58,6 @@ async function getDevServerConfig(wco) {
|
|
|
58
58
|
},
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
const webSocketPath = path_1.posix.join(servePath, 'ws');
|
|
62
61
|
return {
|
|
63
62
|
plugins: extraPlugins,
|
|
64
63
|
module: {
|
|
@@ -82,11 +81,6 @@ async function getDevServerConfig(wco) {
|
|
|
82
81
|
},
|
|
83
82
|
],
|
|
84
83
|
},
|
|
85
|
-
webSocketServer: {
|
|
86
|
-
options: {
|
|
87
|
-
path: webSocketPath,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
84
|
compress: false,
|
|
91
85
|
static: false,
|
|
92
86
|
server: getServerConfig(root, wco.buildOptions),
|
|
@@ -98,14 +92,7 @@ async function getDevServerConfig(wco) {
|
|
|
98
92
|
liveReload,
|
|
99
93
|
hot: hmr && !liveReload ? 'only' : hmr,
|
|
100
94
|
proxy: await addProxyConfig(root, proxyConfig),
|
|
101
|
-
|
|
102
|
-
logging: 'info',
|
|
103
|
-
webSocketURL: getPublicHostOptions(wco.buildOptions, webSocketPath),
|
|
104
|
-
overlay: {
|
|
105
|
-
errors: true,
|
|
106
|
-
warnings: false,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
95
|
+
...getWebSocketSettings(wco.buildOptions, servePath),
|
|
109
96
|
},
|
|
110
97
|
};
|
|
111
98
|
}
|
|
@@ -271,6 +258,31 @@ function getAllowedHostsConfig(options) {
|
|
|
271
258
|
}
|
|
272
259
|
return undefined;
|
|
273
260
|
}
|
|
261
|
+
function getWebSocketSettings(options, servePath) {
|
|
262
|
+
const { hmr, liveReload } = options;
|
|
263
|
+
if (!hmr && !liveReload) {
|
|
264
|
+
return {
|
|
265
|
+
webSocketServer: false,
|
|
266
|
+
client: undefined,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
const webSocketPath = path_1.posix.join(servePath, 'ws');
|
|
270
|
+
return {
|
|
271
|
+
webSocketServer: {
|
|
272
|
+
options: {
|
|
273
|
+
path: webSocketPath,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
client: {
|
|
277
|
+
logging: 'info',
|
|
278
|
+
webSocketURL: getPublicHostOptions(options, webSocketPath),
|
|
279
|
+
overlay: {
|
|
280
|
+
errors: true,
|
|
281
|
+
warnings: false,
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|
|
274
286
|
function getPublicHostOptions(options, webSocketPath) {
|
|
275
287
|
let publicHost = options.publicHost;
|
|
276
288
|
if (publicHost) {
|
|
@@ -25,9 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
__setModuleDefault(result, mod);
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
28
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
32
|
exports.getStylesConfig = void 0;
|
|
30
33
|
const fs = __importStar(require("fs"));
|
|
34
|
+
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
31
35
|
const path = __importStar(require("path"));
|
|
32
36
|
const sass_service_1 = require("../../sass/sass-service");
|
|
33
37
|
const plugins_1 = require("../plugins");
|
|
@@ -70,7 +74,6 @@ function resolveGlobalStyles(styleEntrypoints, root, preserveSymlinks) {
|
|
|
70
74
|
// eslint-disable-next-line max-lines-per-function
|
|
71
75
|
function getStylesConfig(wco) {
|
|
72
76
|
var _a, _b, _c;
|
|
73
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
74
77
|
const postcssImports = require('postcss-import');
|
|
75
78
|
const postcssPresetEnv = require('postcss-preset-env');
|
|
76
79
|
const { root, buildOptions } = wco;
|
|
@@ -129,9 +132,6 @@ function getStylesConfig(wco) {
|
|
|
129
132
|
` To enable Tailwind CSS, please install the 'tailwindcss' package.`);
|
|
130
133
|
}
|
|
131
134
|
if (tailwindPackagePath) {
|
|
132
|
-
if (process.env['TAILWIND_MODE'] === undefined) {
|
|
133
|
-
process.env['TAILWIND_MODE'] = buildOptions.watch ? 'watch' : 'build';
|
|
134
|
-
}
|
|
135
135
|
extraPostcssPlugins.push(require(tailwindPackagePath)({ config: tailwindConfigPath }));
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -191,7 +191,7 @@ function getStylesConfig(wco) {
|
|
|
191
191
|
// for component css.
|
|
192
192
|
!buildOptions.sourceMap.hidden);
|
|
193
193
|
// extract global css from js files into own css file.
|
|
194
|
-
extraPlugins.push(new
|
|
194
|
+
extraPlugins.push(new mini_css_extract_plugin_1.default({ filename: `[name]${hashFormat.extract}.css` }));
|
|
195
195
|
if (!buildOptions.hmr) {
|
|
196
196
|
// don't remove `.js` files for `.css` when we are using HMR these contain HMR accept codes.
|
|
197
197
|
// suppress empty .js files in css only entry points.
|
|
@@ -210,7 +210,7 @@ function getStylesConfig(wco) {
|
|
|
210
210
|
];
|
|
211
211
|
const globalStyleLoaders = [
|
|
212
212
|
{
|
|
213
|
-
loader:
|
|
213
|
+
loader: mini_css_extract_plugin_1.default.loader,
|
|
214
214
|
},
|
|
215
215
|
{
|
|
216
216
|
loader: require.resolve('css-loader'),
|
|
@@ -340,17 +340,17 @@ function getStylesConfig(wco) {
|
|
|
340
340
|
// Setup processing rules for global and component styles
|
|
341
341
|
{
|
|
342
342
|
oneOf: [
|
|
343
|
-
// Component styles are all styles except defined global styles
|
|
344
|
-
{
|
|
345
|
-
use: componentStyleLoaders,
|
|
346
|
-
resourceQuery: /\?ngResource/,
|
|
347
|
-
type: 'asset/source',
|
|
348
|
-
},
|
|
349
343
|
// Global styles are only defined global styles
|
|
350
344
|
{
|
|
351
345
|
use: globalStyleLoaders,
|
|
346
|
+
include: globalStylePaths,
|
|
352
347
|
resourceQuery: { not: [/\?ngResource/] },
|
|
353
348
|
},
|
|
349
|
+
// Component styles are all styles except defined global styles
|
|
350
|
+
{
|
|
351
|
+
use: componentStyleLoaders,
|
|
352
|
+
type: 'asset/source',
|
|
353
|
+
},
|
|
354
354
|
],
|
|
355
355
|
},
|
|
356
356
|
{ use },
|
|
@@ -47,6 +47,10 @@ class AnyComponentStyleBudgetChecker {
|
|
|
47
47
|
name: PLUGIN_NAME,
|
|
48
48
|
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
49
49
|
}, () => {
|
|
50
|
+
// No budgets.
|
|
51
|
+
if (this.budgets.length === 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
50
54
|
// In AOT compilations component styles get processed in child compilations.
|
|
51
55
|
if (!compilation.compiler.parentCompilation) {
|
|
52
56
|
return;
|
|
@@ -13,10 +13,10 @@ import type { Compiler } from 'webpack';
|
|
|
13
13
|
export interface JavaScriptOptimizerOptions {
|
|
14
14
|
/**
|
|
15
15
|
* Enables advanced optimizations in the underlying JavaScript optimizers.
|
|
16
|
-
* This currently increases the `terser` passes to
|
|
16
|
+
* This currently increases the `terser` passes to 2 and enables the `pure_getters`
|
|
17
17
|
* option for `terser`.
|
|
18
18
|
*/
|
|
19
|
-
advanced
|
|
19
|
+
advanced?: boolean;
|
|
20
20
|
/**
|
|
21
21
|
* An object record of string keys that will be replaced with their respective values when found
|
|
22
22
|
* within the code during optimization.
|
|
@@ -27,7 +27,7 @@ export interface JavaScriptOptimizerOptions {
|
|
|
27
27
|
* The output sourcemap will be a full sourcemap containing the merge of the input sourcemap and
|
|
28
28
|
* all intermediate sourcemaps.
|
|
29
29
|
*/
|
|
30
|
-
sourcemap
|
|
30
|
+
sourcemap?: boolean;
|
|
31
31
|
/**
|
|
32
32
|
* The ECMAScript version that should be used when generating output code.
|
|
33
33
|
* The optimizer will not adjust the output code with features present in newer
|
|
@@ -37,12 +37,20 @@ export interface JavaScriptOptimizerOptions {
|
|
|
37
37
|
/**
|
|
38
38
|
* Enables the retention of identifier names and ensures that function and class names are
|
|
39
39
|
* present in the output code.
|
|
40
|
+
*
|
|
41
|
+
* **Note**: in some cases symbols are still renamed to avoid collisions.
|
|
42
|
+
*/
|
|
43
|
+
keepIdentifierNames: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Enables the retention of original name of classes and functions.
|
|
46
|
+
*
|
|
47
|
+
* **Note**: this causes increase of bundle size as it causes dead-code elimination to not work fully.
|
|
40
48
|
*/
|
|
41
49
|
keepNames: boolean;
|
|
42
50
|
/**
|
|
43
51
|
* Enables the removal of all license comments from the output code.
|
|
44
52
|
*/
|
|
45
|
-
removeLicenses
|
|
53
|
+
removeLicenses?: boolean;
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
56
|
* A Webpack plugin that provides JavaScript optimization capabilities.
|
|
@@ -53,7 +61,7 @@ export interface JavaScriptOptimizerOptions {
|
|
|
53
61
|
* optimizations not yet implemented by `esbuild`.
|
|
54
62
|
*/
|
|
55
63
|
export declare class JavaScriptOptimizerPlugin {
|
|
56
|
-
options:
|
|
57
|
-
constructor(options
|
|
64
|
+
options: JavaScriptOptimizerOptions;
|
|
65
|
+
constructor(options: JavaScriptOptimizerOptions);
|
|
58
66
|
apply(compiler: Compiler): void;
|
|
59
67
|
}
|
|
@@ -32,7 +32,7 @@ const PLUGIN_NAME = 'angular-javascript-optimizer';
|
|
|
32
32
|
* optimizations not yet implemented by `esbuild`.
|
|
33
33
|
*/
|
|
34
34
|
class JavaScriptOptimizerPlugin {
|
|
35
|
-
constructor(options
|
|
35
|
+
constructor(options) {
|
|
36
36
|
this.options = options;
|
|
37
37
|
}
|
|
38
38
|
apply(compiler) {
|
|
@@ -91,11 +91,11 @@ class JavaScriptOptimizerPlugin {
|
|
|
91
91
|
if (this.options.target <= typescript_1.ScriptTarget.ES5) {
|
|
92
92
|
target = 5;
|
|
93
93
|
}
|
|
94
|
-
else if (this.options.target
|
|
95
|
-
target =
|
|
94
|
+
else if (this.options.target === typescript_1.ScriptTarget.ESNext) {
|
|
95
|
+
target = 'next';
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
|
-
target =
|
|
98
|
+
target = Number(typescript_1.ScriptTarget[this.options.target].slice(2));
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
// Setup the options used by all worker tasks
|
|
@@ -103,6 +103,7 @@ class JavaScriptOptimizerPlugin {
|
|
|
103
103
|
sourcemap: this.options.sourcemap,
|
|
104
104
|
define,
|
|
105
105
|
keepNames: this.options.keepNames,
|
|
106
|
+
keepIdentifierNames: this.options.keepIdentifierNames,
|
|
106
107
|
target,
|
|
107
108
|
removeLicenses: this.options.removeLicenses,
|
|
108
109
|
advanced: this.options.advanced,
|
|
@@ -5,6 +5,50 @@
|
|
|
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
|
+
* The options to use when optimizing.
|
|
10
|
+
*/
|
|
11
|
+
export interface OptimizeRequestOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Controls advanced optimizations.
|
|
14
|
+
* Currently these are only terser related:
|
|
15
|
+
* * terser compress passes are set to 2
|
|
16
|
+
* * terser pure_getters option is enabled
|
|
17
|
+
*/
|
|
18
|
+
advanced?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Specifies the string tokens that should be replaced with a defined value.
|
|
21
|
+
*/
|
|
22
|
+
define?: Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Controls whether class, function, and variable names should be left intact
|
|
25
|
+
* throughout the output code.
|
|
26
|
+
*/
|
|
27
|
+
keepIdentifierNames: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Controls whether to retain the original name of classes and functions.
|
|
30
|
+
*/
|
|
31
|
+
keepNames: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Controls whether license text is removed from the output code.
|
|
34
|
+
* Within the CLI, this option is linked to the license extraction functionality.
|
|
35
|
+
*/
|
|
36
|
+
removeLicenses?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Controls whether source maps should be generated.
|
|
39
|
+
*/
|
|
40
|
+
sourcemap?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Specifies the target ECMAScript version for the output code.
|
|
43
|
+
*/
|
|
44
|
+
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 'next';
|
|
45
|
+
/**
|
|
46
|
+
* Controls whether esbuild should only use the WASM-variant instead of trying to
|
|
47
|
+
* use the native variant. Some platforms may not support the native-variant and
|
|
48
|
+
* this option allows one support test to be conducted prior to all the workers starting.
|
|
49
|
+
*/
|
|
50
|
+
alwaysUseWasm: boolean;
|
|
51
|
+
}
|
|
8
52
|
/**
|
|
9
53
|
* A request to optimize JavaScript using the supplied options.
|
|
10
54
|
*/
|
|
@@ -12,43 +56,7 @@ interface OptimizeRequest {
|
|
|
12
56
|
/**
|
|
13
57
|
* The options to use when optimizing.
|
|
14
58
|
*/
|
|
15
|
-
options:
|
|
16
|
-
/**
|
|
17
|
-
* Controls advanced optimizations.
|
|
18
|
-
* Currently these are only terser related:
|
|
19
|
-
* * terser compress passes are set to 2
|
|
20
|
-
* * terser pure_getters option is enabled
|
|
21
|
-
*/
|
|
22
|
-
advanced: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Specifies the string tokens that should be replaced with a defined value.
|
|
25
|
-
*/
|
|
26
|
-
define?: Record<string, string>;
|
|
27
|
-
/**
|
|
28
|
-
* Controls whether class, function, and variable names should be left intact
|
|
29
|
-
* throughout the output code.
|
|
30
|
-
*/
|
|
31
|
-
keepNames: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Controls whether license text is removed from the output code.
|
|
34
|
-
* Within the CLI, this option is linked to the license extraction functionality.
|
|
35
|
-
*/
|
|
36
|
-
removeLicenses: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Controls whether source maps should be generated.
|
|
39
|
-
*/
|
|
40
|
-
sourcemap: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Specifies the target ECMAScript version for the output code.
|
|
43
|
-
*/
|
|
44
|
-
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
|
|
45
|
-
/**
|
|
46
|
-
* Controls whether esbuild should only use the WASM-variant instead of trying to
|
|
47
|
-
* use the native variant. Some platforms may not support the native-variant and
|
|
48
|
-
* this option allows one support test to be conducted prior to all the workers starting.
|
|
49
|
-
*/
|
|
50
|
-
alwaysUseWasm: boolean;
|
|
51
|
-
};
|
|
59
|
+
options: OptimizeRequestOptions;
|
|
52
60
|
/**
|
|
53
61
|
* The JavaScript asset to optimize.
|
|
54
62
|
*/
|
|
@@ -26,7 +26,9 @@ async function default_1({ asset, options }) {
|
|
|
26
26
|
// esbuild is used as a first pass
|
|
27
27
|
const esbuildResult = await optimizeWithEsbuild(asset.code, asset.name, options);
|
|
28
28
|
// terser is used as a second pass
|
|
29
|
-
const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap,
|
|
29
|
+
const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap,
|
|
30
|
+
// Terser only supports up to ES2020.
|
|
31
|
+
options.target === 'next' ? 2020 : options.target, options.advanced);
|
|
30
32
|
// Merge intermediate sourcemaps with input sourcemap if enabled
|
|
31
33
|
let fullSourcemap;
|
|
32
34
|
if (options.sourcemap) {
|
|
@@ -61,7 +63,7 @@ async function optimizeWithEsbuild(content, name, options) {
|
|
|
61
63
|
let result;
|
|
62
64
|
try {
|
|
63
65
|
result = await esbuild.transform(content, {
|
|
64
|
-
minifyIdentifiers: !options.
|
|
66
|
+
minifyIdentifiers: !options.keepIdentifierNames,
|
|
65
67
|
minifySyntax: true,
|
|
66
68
|
// NOTE: Disabling whitespace ensures unused pure annotations are kept
|
|
67
69
|
minifyWhitespace: false,
|
|
@@ -70,6 +72,10 @@ async function optimizeWithEsbuild(content, name, options) {
|
|
|
70
72
|
sourcefile: name,
|
|
71
73
|
sourcemap: options.sourcemap && 'external',
|
|
72
74
|
define: options.define,
|
|
75
|
+
// This option should always be disabled for browser builds as we don't rely on `.name`
|
|
76
|
+
// and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
|
|
77
|
+
// We enable `keepNames` only for server builds as Domino relies on `.name`.
|
|
78
|
+
// Once we no longer rely on Domino for SSR we should be able to remove this.
|
|
73
79
|
keepNames: options.keepNames,
|
|
74
80
|
target: `es${options.target}`,
|
|
75
81
|
});
|
|
@@ -113,6 +119,8 @@ async function optimizeWithTerser(name, code, sourcemaps, target, advanced) {
|
|
|
113
119
|
ecma: target,
|
|
114
120
|
// esbuild in the first pass is used to minify identifiers instead of mangle here
|
|
115
121
|
mangle: false,
|
|
122
|
+
// esbuild in the first pass is used to minify function names
|
|
123
|
+
keep_fnames: true,
|
|
116
124
|
format: {
|
|
117
125
|
// ASCII output is enabled here as well to prevent terser from converting back to UTF-8
|
|
118
126
|
ascii_only: true,
|
|
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
const path = __importStar(require("path"));
|
|
33
33
|
const glob = __importStar(require("glob"));
|
|
34
34
|
const webpack_1 = __importDefault(require("webpack"));
|
|
35
|
-
const
|
|
35
|
+
const webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
|
|
36
36
|
const stats_1 = require("../../utils/stats");
|
|
37
37
|
const node_1 = require("@angular-devkit/core/node");
|
|
38
38
|
const index_1 = require("../../../utils/index");
|
|
@@ -172,7 +172,7 @@ const init = (config, emitter) => {
|
|
|
172
172
|
}
|
|
173
173
|
unblock();
|
|
174
174
|
});
|
|
175
|
-
webpackMiddleware =
|
|
175
|
+
webpackMiddleware = (0, webpack_dev_middleware_1.default)(compiler, webpackMiddlewareConfig);
|
|
176
176
|
emitter.on('exit', (done) => {
|
|
177
177
|
webpackMiddleware.close();
|
|
178
178
|
done();
|