@angular-devkit/build-angular 13.0.0-next.3 → 13.0.0-next.7
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/esbuild-check.js +16 -0
- package/package.json +32 -29
- package/src/babel/plugins/adjust-static-class-members.js +2 -2
- package/src/babel/plugins/adjust-typescript-enums.js +8 -2
- package/src/babel/plugins/pure-toplevel-functions.js +2 -2
- package/src/babel/presets/application.d.ts +14 -0
- package/src/babel/presets/application.js +42 -36
- package/src/babel/webpack-loader.js +50 -5
- package/src/builders/app-shell/index.js +9 -9
- package/src/builders/browser/index.js +42 -52
- package/src/builders/dev-server/index.js +23 -23
- package/src/builders/extract-i18n/index.js +33 -21
- package/src/builders/extract-i18n/ivy-extract-loader.js +34 -8
- package/src/builders/karma/find-tests.js +5 -5
- package/src/builders/karma/index.js +14 -14
- package/src/builders/ng-packagr/index.js +4 -4
- package/src/builders/protractor/index.js +4 -4
- package/src/builders/server/index.js +16 -16
- package/src/sass/worker.js +2 -2
- package/src/utils/build-browser-features.js +2 -2
- package/src/utils/build-options.d.ts +1 -1
- package/src/utils/bundle-calculator.js +4 -4
- package/src/utils/cache-path.js +2 -2
- package/src/utils/check-port.js +1 -1
- package/src/utils/color.js +25 -2
- package/src/utils/copy-assets.js +1 -1
- package/src/utils/delete-output-dir.js +1 -1
- package/src/utils/i18n-inlining.js +1 -1
- package/src/utils/i18n-options.js +26 -50
- package/src/utils/index-file/augment-index-html.js +2 -2
- package/src/utils/index-file/index-html-generator.js +3 -3
- package/src/utils/index-file/inline-fonts.js +4 -4
- package/src/utils/load-esm.d.ts +22 -0
- package/src/utils/load-esm.js +37 -0
- package/src/utils/load-translations.js +21 -8
- package/src/utils/normalize-asset-patterns.js +8 -8
- package/src/utils/normalize-builder-schema.js +4 -4
- package/src/utils/normalize-file-replacements.js +10 -10
- package/src/utils/output-paths.js +3 -3
- package/src/utils/package-chunk-sort.js +1 -1
- package/src/utils/process-bundle.d.ts +0 -1
- package/src/utils/process-bundle.js +44 -12
- package/src/utils/read-tsconfig.d.ts +2 -2
- package/src/utils/read-tsconfig.js +11 -6
- package/src/utils/run-module-as-observable-fork.js +2 -2
- package/src/utils/service-worker.js +16 -9
- package/src/utils/spinner.js +2 -2
- package/src/utils/version.js +1 -1
- package/src/utils/webpack-browser-config.d.ts +4 -3
- package/src/utils/webpack-browser-config.js +12 -11
- package/src/webpack/configs/browser.js +1 -1
- package/src/webpack/configs/common.d.ts +1 -1
- package/src/webpack/configs/common.js +24 -16
- package/src/webpack/configs/dev-server.d.ts +1 -1
- package/src/webpack/configs/dev-server.js +22 -10
- package/src/webpack/configs/server.js +2 -2
- package/src/webpack/configs/styles.js +4 -4
- package/src/webpack/configs/test.js +2 -2
- package/src/webpack/configs/typescript.js +1 -1
- package/src/webpack/configs/worker.js +1 -1
- package/src/webpack/plugins/any-component-style-budget-checker.js +4 -4
- package/src/webpack/plugins/common-js-usage-warn-plugin.js +2 -2
- package/src/webpack/plugins/css-optimizer-plugin.d.ts +12 -0
- package/src/webpack/plugins/css-optimizer-plugin.js +43 -17
- package/src/webpack/plugins/dedupe-module-resolve-plugin.js +1 -1
- package/src/webpack/plugins/esbuild-executor.d.ts +46 -0
- package/src/webpack/plugins/esbuild-executor.js +126 -0
- package/src/webpack/plugins/hmr/hmr-accept.js +3 -3
- package/src/webpack/plugins/hmr/hmr-loader.js +1 -1
- package/src/webpack/plugins/index-html-webpack-plugin.js +6 -6
- package/src/webpack/plugins/javascript-optimizer-plugin.js +5 -0
- package/src/webpack/plugins/javascript-optimizer-worker.d.ts +42 -0
- package/src/webpack/plugins/javascript-optimizer-worker.js +63 -27
- package/src/webpack/plugins/karma/karma.js +4 -4
- package/src/webpack/plugins/postcss-cli-resources.js +1 -1
- package/src/webpack/plugins/scripts-webpack-plugin.js +1 -1
- package/src/webpack/plugins/single-test-transform.js +1 -1
- package/src/webpack/utils/stats.js +6 -6
|
@@ -30,7 +30,6 @@ 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 compiler_cli_1 = require("@angular/compiler-cli");
|
|
34
33
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
35
34
|
const crypto_1 = require("crypto");
|
|
36
35
|
const fs_1 = require("fs");
|
|
@@ -40,21 +39,29 @@ const webpack_1 = require("webpack");
|
|
|
40
39
|
const utils_1 = require("../../utils");
|
|
41
40
|
const cache_path_1 = require("../../utils/cache-path");
|
|
42
41
|
const environment_options_1 = require("../../utils/environment-options");
|
|
42
|
+
const load_esm_1 = require("../../utils/load-esm");
|
|
43
43
|
const spinner_1 = require("../../utils/spinner");
|
|
44
44
|
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
|
|
45
45
|
const plugins_1 = require("../plugins");
|
|
46
46
|
const javascript_optimizer_plugin_1 = require("../plugins/javascript-optimizer-plugin");
|
|
47
47
|
const helpers_1 = require("../utils/helpers");
|
|
48
48
|
// eslint-disable-next-line max-lines-per-function
|
|
49
|
-
function getCommonConfig(wco) {
|
|
49
|
+
async function getCommonConfig(wco) {
|
|
50
50
|
var _a, _b;
|
|
51
51
|
const { root, projectRoot, buildOptions, tsConfig } = wco;
|
|
52
52
|
const { platform = 'browser', sourceMap: { styles: stylesSourceMap, scripts: scriptsSourceMap, vendor: vendorSourceMap }, optimization: { styles: stylesOptimization, scripts: scriptsOptimization }, } = buildOptions;
|
|
53
53
|
const extraPlugins = [];
|
|
54
54
|
const extraRules = [];
|
|
55
55
|
const entryPoints = {};
|
|
56
|
+
// Load ESM `@angular/compiler-cli` using the TypeScript dynamic import workaround.
|
|
57
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
58
|
+
// changed to a direct dynamic import.
|
|
59
|
+
const compilerCliModule = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli');
|
|
60
|
+
// If it is not ESM then the values needed will be stored in the `default` property.
|
|
61
|
+
// TODO_ESM: This can be removed once `@angular/compiler-cli` is ESM only.
|
|
62
|
+
const { GLOBAL_DEFS_FOR_TERSER, GLOBAL_DEFS_FOR_TERSER_WITH_AOT, VERSION: NG_VERSION, } = (compilerCliModule.GLOBAL_DEFS_FOR_TERSER ? compilerCliModule : compilerCliModule.default);
|
|
56
63
|
// determine hashing format
|
|
57
|
-
const hashFormat = helpers_1.getOutputHashFormat(buildOptions.outputHashing || 'none');
|
|
64
|
+
const hashFormat = (0, helpers_1.getOutputHashFormat)(buildOptions.outputHashing || 'none');
|
|
58
65
|
const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot);
|
|
59
66
|
if (buildOptions.progress) {
|
|
60
67
|
const spinner = new spinner_1.Spinner();
|
|
@@ -108,10 +115,10 @@ function getCommonConfig(wco) {
|
|
|
108
115
|
}));
|
|
109
116
|
}
|
|
110
117
|
// process global scripts
|
|
111
|
-
const globalScriptsByBundleName = helpers_1.normalizeExtraEntryPoints(buildOptions.scripts, 'scripts').reduce((prev, curr) => {
|
|
118
|
+
const globalScriptsByBundleName = (0, helpers_1.normalizeExtraEntryPoints)(buildOptions.scripts, 'scripts').reduce((prev, curr) => {
|
|
112
119
|
const { bundleName, inject, input } = curr;
|
|
113
120
|
let resolvedPath = path.resolve(root, input);
|
|
114
|
-
if (!fs_1.existsSync(resolvedPath)) {
|
|
121
|
+
if (!(0, fs_1.existsSync)(resolvedPath)) {
|
|
115
122
|
try {
|
|
116
123
|
resolvedPath = require.resolve(input, { paths: [root] });
|
|
117
124
|
}
|
|
@@ -216,12 +223,12 @@ function getCommonConfig(wco) {
|
|
|
216
223
|
try {
|
|
217
224
|
await fs_1.promises.mkdir(path.dirname(statsOutputPath), { recursive: true });
|
|
218
225
|
await new Promise((resolve, reject) => stringifyStream(data)
|
|
219
|
-
.pipe(fs_1.createWriteStream(statsOutputPath))
|
|
226
|
+
.pipe((0, fs_1.createWriteStream)(statsOutputPath))
|
|
220
227
|
.on('close', resolve)
|
|
221
228
|
.on('error', reject));
|
|
222
229
|
}
|
|
223
230
|
catch (error) {
|
|
224
|
-
webpack_diagnostics_1.addError(stats.compilation, `Unable to write stats file: ${error.message || 'unknown error'}`);
|
|
231
|
+
(0, webpack_diagnostics_1.addError)(stats.compilation, `Unable to write stats file: ${error.message || 'unknown error'}`);
|
|
225
232
|
}
|
|
226
233
|
});
|
|
227
234
|
}
|
|
@@ -248,7 +255,7 @@ function getCommonConfig(wco) {
|
|
|
248
255
|
const extraMinimizers = [];
|
|
249
256
|
if (scriptsOptimization) {
|
|
250
257
|
extraMinimizers.push(new javascript_optimizer_plugin_1.JavaScriptOptimizerPlugin({
|
|
251
|
-
define: buildOptions.aot ?
|
|
258
|
+
define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
|
|
252
259
|
sourcemap: scriptsSourceMap,
|
|
253
260
|
target: wco.scriptTarget,
|
|
254
261
|
keepNames: !environment_options_1.allowMangle || platform === 'server',
|
|
@@ -276,6 +283,7 @@ function getCommonConfig(wco) {
|
|
|
276
283
|
context: root,
|
|
277
284
|
entry: entryPoints,
|
|
278
285
|
output: {
|
|
286
|
+
hashFunction: 'xxhash64',
|
|
279
287
|
clean: (_a = buildOptions.deleteOutputPath) !== null && _a !== void 0 ? _a : true,
|
|
280
288
|
path: path.resolve(root, buildOptions.outputPath),
|
|
281
289
|
publicPath: (_b = buildOptions.deployUrl) !== null && _b !== void 0 ? _b : '',
|
|
@@ -283,7 +291,7 @@ function getCommonConfig(wco) {
|
|
|
283
291
|
chunkFilename: `[name]${hashFormat.chunk}.js`,
|
|
284
292
|
},
|
|
285
293
|
watch: buildOptions.watch,
|
|
286
|
-
watchOptions: helpers_1.getWatchOptions(buildOptions.poll),
|
|
294
|
+
watchOptions: (0, helpers_1.getWatchOptions)(buildOptions.poll),
|
|
287
295
|
performance: {
|
|
288
296
|
hints: false,
|
|
289
297
|
},
|
|
@@ -317,12 +325,12 @@ function getCommonConfig(wco) {
|
|
|
317
325
|
test: /\.[cm]?js$|\.tsx?$/,
|
|
318
326
|
// The below is needed due to a bug in `@babel/runtime`. See: https://github.com/babel/babel/issues/12824
|
|
319
327
|
resolve: { fullySpecified: false },
|
|
320
|
-
exclude: [/[/\\](?:core-js|@babel|tslib|web-animations-js)[/\\]/],
|
|
328
|
+
exclude: [/[/\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\]/],
|
|
321
329
|
use: [
|
|
322
330
|
{
|
|
323
331
|
loader: require.resolve('../../babel/webpack-loader'),
|
|
324
332
|
options: {
|
|
325
|
-
cacheDirectory: cache_path_1.findCachePath('babel-webpack'),
|
|
333
|
+
cacheDirectory: (0, cache_path_1.findCachePath)('babel-webpack'),
|
|
326
334
|
scriptTarget: wco.scriptTarget,
|
|
327
335
|
aot: buildOptions.aot,
|
|
328
336
|
optimize: buildOptions.buildOptimizer,
|
|
@@ -340,7 +348,7 @@ function getCommonConfig(wco) {
|
|
|
340
348
|
infrastructureLogging: {
|
|
341
349
|
level: buildOptions.verbose ? 'verbose' : 'error',
|
|
342
350
|
},
|
|
343
|
-
cache: getCacheSettings(wco, buildBrowserFeatures.supportedBrowsers),
|
|
351
|
+
cache: getCacheSettings(wco, buildBrowserFeatures.supportedBrowsers, NG_VERSION.full),
|
|
344
352
|
optimization: {
|
|
345
353
|
minimizer: extraMinimizers,
|
|
346
354
|
moduleIds: 'deterministic',
|
|
@@ -357,18 +365,18 @@ function getCommonConfig(wco) {
|
|
|
357
365
|
};
|
|
358
366
|
}
|
|
359
367
|
exports.getCommonConfig = getCommonConfig;
|
|
360
|
-
function getCacheSettings(wco, supportedBrowsers) {
|
|
368
|
+
function getCacheSettings(wco, supportedBrowsers, angularVersion) {
|
|
361
369
|
if (environment_options_1.persistentBuildCacheEnabled) {
|
|
362
370
|
const packageVersion = require('../../../package.json').version;
|
|
363
371
|
return {
|
|
364
372
|
type: 'filesystem',
|
|
365
|
-
cacheDirectory: cache_path_1.findCachePath('angular-webpack'),
|
|
373
|
+
cacheDirectory: (0, cache_path_1.findCachePath)('angular-webpack'),
|
|
366
374
|
maxMemoryGenerations: 1,
|
|
367
375
|
// We use the versions and build options as the cache name. The Webpack configurations are too
|
|
368
376
|
// dynamic and shared among different build types: test, build and serve.
|
|
369
377
|
// None of which are "named".
|
|
370
|
-
name: crypto_1.createHash('sha1')
|
|
371
|
-
.update(
|
|
378
|
+
name: (0, crypto_1.createHash)('sha1')
|
|
379
|
+
.update(angularVersion)
|
|
372
380
|
.update(packageVersion)
|
|
373
381
|
.update(wco.projectRoot)
|
|
374
382
|
.update(JSON.stringify(wco.tsConfig))
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { logging } from '@angular-devkit/core';
|
|
9
9
|
import * as webpack from 'webpack';
|
|
10
10
|
import { WebpackConfigOptions, WebpackDevServerOptions } from '../../utils/build-options';
|
|
11
|
-
export declare function getDevServerConfig(wco: WebpackConfigOptions<WebpackDevServerOptions>): webpack.Configuration
|
|
11
|
+
export declare function getDevServerConfig(wco: WebpackConfigOptions<WebpackDevServerOptions>): Promise<webpack.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.
|
|
@@ -31,16 +31,17 @@ const core_1 = require("@angular-devkit/core");
|
|
|
31
31
|
const fs_1 = require("fs");
|
|
32
32
|
const path_1 = require("path");
|
|
33
33
|
const url = __importStar(require("url"));
|
|
34
|
+
const load_esm_1 = require("../../utils/load-esm");
|
|
34
35
|
const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
|
|
35
36
|
const hmr_loader_1 = require("../plugins/hmr/hmr-loader");
|
|
36
|
-
function getDevServerConfig(wco) {
|
|
37
|
+
async function getDevServerConfig(wco) {
|
|
37
38
|
const { buildOptions: { host, port, index, headers, watch, hmr, main, liveReload, proxyConfig }, logger, root, } = wco;
|
|
38
39
|
const servePath = buildServePath(wco.buildOptions, logger);
|
|
39
40
|
const extraRules = [];
|
|
40
41
|
if (hmr) {
|
|
41
42
|
extraRules.push({
|
|
42
43
|
loader: hmr_loader_1.HmrLoader,
|
|
43
|
-
include: [main].map((p) => path_1.resolve(wco.root, p)),
|
|
44
|
+
include: [main].map((p) => (0, path_1.resolve)(wco.root, p)),
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
const extraPlugins = [];
|
|
@@ -71,7 +72,7 @@ function getDevServerConfig(wco) {
|
|
|
71
72
|
...headers,
|
|
72
73
|
},
|
|
73
74
|
historyApiFallback: !!index && {
|
|
74
|
-
index: path_1.posix.join(servePath, webpack_browser_config_1.getIndexOutputFile(index)),
|
|
75
|
+
index: path_1.posix.join(servePath, (0, webpack_browser_config_1.getIndexOutputFile)(index)),
|
|
75
76
|
disableDotRule: true,
|
|
76
77
|
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
77
78
|
rewrites: [
|
|
@@ -96,7 +97,7 @@ function getDevServerConfig(wco) {
|
|
|
96
97
|
},
|
|
97
98
|
liveReload,
|
|
98
99
|
hot: hmr && !liveReload ? 'only' : hmr,
|
|
99
|
-
proxy: addProxyConfig(root, proxyConfig),
|
|
100
|
+
proxy: await addProxyConfig(root, proxyConfig),
|
|
100
101
|
client: {
|
|
101
102
|
logging: 'info',
|
|
102
103
|
webSocketURL: getPublicHostOptions(wco.buildOptions, webSocketPath),
|
|
@@ -142,8 +143,8 @@ function getSslConfig(root, options) {
|
|
|
142
143
|
const { ssl, sslCert, sslKey } = options;
|
|
143
144
|
if (ssl && sslCert && sslKey) {
|
|
144
145
|
return {
|
|
145
|
-
key:
|
|
146
|
-
cert:
|
|
146
|
+
key: (0, path_1.resolve)(root, sslKey),
|
|
147
|
+
cert: (0, path_1.resolve)(root, sslCert),
|
|
147
148
|
};
|
|
148
149
|
}
|
|
149
150
|
return ssl;
|
|
@@ -152,13 +153,24 @@ function getSslConfig(root, options) {
|
|
|
152
153
|
* Private method to enhance a webpack config with Proxy configuration.
|
|
153
154
|
* @private
|
|
154
155
|
*/
|
|
155
|
-
function addProxyConfig(root, proxyConfig) {
|
|
156
|
+
async function addProxyConfig(root, proxyConfig) {
|
|
156
157
|
if (!proxyConfig) {
|
|
157
158
|
return undefined;
|
|
158
159
|
}
|
|
159
|
-
const proxyPath = path_1.resolve(root, proxyConfig);
|
|
160
|
-
if (fs_1.existsSync(proxyPath)) {
|
|
161
|
-
|
|
160
|
+
const proxyPath = (0, path_1.resolve)(root, proxyConfig);
|
|
161
|
+
if ((0, fs_1.existsSync)(proxyPath)) {
|
|
162
|
+
try {
|
|
163
|
+
return require(proxyPath);
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
if (e.code === 'ERR_REQUIRE_ESM') {
|
|
167
|
+
// Load the ESM configuration file using the TypeScript dynamic import workaround.
|
|
168
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
169
|
+
// changed to a direct dynamic import.
|
|
170
|
+
return (await (0, load_esm_1.loadEsmModule)(url.pathToFileURL(proxyPath))).default;
|
|
171
|
+
}
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
162
174
|
}
|
|
163
175
|
throw new Error('Proxy config file ' + proxyPath + ' does not exist.');
|
|
164
176
|
}
|
|
@@ -20,7 +20,7 @@ function getServerConfig(wco) {
|
|
|
20
20
|
const extraPlugins = [];
|
|
21
21
|
const { scripts, styles, hidden } = sourceMap;
|
|
22
22
|
if (scripts || styles) {
|
|
23
|
-
extraPlugins.push(helpers_1.getSourceMapDevTool(scripts, styles, hidden));
|
|
23
|
+
extraPlugins.push((0, helpers_1.getSourceMapDevTool)(scripts, styles, hidden));
|
|
24
24
|
}
|
|
25
25
|
const externals = [...externalDependencies];
|
|
26
26
|
if (!bundleDependencies) {
|
|
@@ -58,7 +58,7 @@ function externalizePackages(context, request, callback) {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
// Absolute & Relative paths are not externals
|
|
61
|
-
if (request.startsWith('.') || path_1.isAbsolute(request)) {
|
|
61
|
+
if (request.startsWith('.') || (0, path_1.isAbsolute)(request)) {
|
|
62
62
|
callback();
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
@@ -41,7 +41,7 @@ function resolveGlobalStyles(styleEntrypoints, root, preserveSymlinks) {
|
|
|
41
41
|
if (styleEntrypoints.length === 0) {
|
|
42
42
|
return { entryPoints, noInjectNames, paths };
|
|
43
43
|
}
|
|
44
|
-
for (const style of helpers_1.normalizeExtraEntryPoints(styleEntrypoints, 'styles')) {
|
|
44
|
+
for (const style of (0, helpers_1.normalizeExtraEntryPoints)(styleEntrypoints, 'styles')) {
|
|
45
45
|
let resolvedPath = path.resolve(root, style.input);
|
|
46
46
|
if (!fs.existsSync(resolvedPath)) {
|
|
47
47
|
try {
|
|
@@ -79,7 +79,7 @@ function getStylesConfig(wco) {
|
|
|
79
79
|
extraPlugins.push(new plugins_1.AnyComponentStyleBudgetChecker(buildOptions.budgets));
|
|
80
80
|
const cssSourceMap = buildOptions.sourceMap.styles;
|
|
81
81
|
// Determine hashing format.
|
|
82
|
-
const hashFormat = helpers_1.getOutputHashFormat(buildOptions.outputHashing);
|
|
82
|
+
const hashFormat = (0, helpers_1.getOutputHashFormat)(buildOptions.outputHashing);
|
|
83
83
|
// use includePaths from appConfig
|
|
84
84
|
const includePaths = (_c = (_b = (_a = buildOptions.stylePreprocessorOptions) === null || _a === void 0 ? void 0 : _a.includePaths) === null || _b === void 0 ? void 0 : _b.map((p) => path.resolve(root, p))) !== null && _c !== void 0 ? _c : [];
|
|
85
85
|
// Process global styles.
|
|
@@ -100,7 +100,7 @@ function getStylesConfig(wco) {
|
|
|
100
100
|
});
|
|
101
101
|
},
|
|
102
102
|
});
|
|
103
|
-
const assetNameTemplate = helpers_1.assetNameTemplateFactory(hashFormat);
|
|
103
|
+
const assetNameTemplate = (0, helpers_1.assetNameTemplateFactory)(hashFormat);
|
|
104
104
|
const extraPostcssPlugins = [];
|
|
105
105
|
// Attempt to setup Tailwind CSS
|
|
106
106
|
// A configuration file can exist in the project or workspace root
|
|
@@ -165,7 +165,7 @@ function getStylesConfig(wco) {
|
|
|
165
165
|
});
|
|
166
166
|
},
|
|
167
167
|
}),
|
|
168
|
-
plugins_1.PostcssCliResources({
|
|
168
|
+
(0, plugins_1.PostcssCliResources)({
|
|
169
169
|
baseHref: buildOptions.baseHref,
|
|
170
170
|
deployUrl: buildOptions.deployUrl,
|
|
171
171
|
resourcesOutputPath: buildOptions.resourcesOutputPath,
|
|
@@ -54,7 +54,7 @@ function getTestConfig(wco) {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
if (sourceMap.scripts || sourceMap.styles) {
|
|
57
|
-
extraPlugins.push(helpers_1.getSourceMapDevTool(sourceMap.scripts, sourceMap.styles, false, true));
|
|
57
|
+
extraPlugins.push((0, helpers_1.getSourceMapDevTool)(sourceMap.scripts, sourceMap.styles, false, true));
|
|
58
58
|
}
|
|
59
59
|
return {
|
|
60
60
|
mode: 'development',
|
|
@@ -80,7 +80,7 @@ function getTestConfig(wco) {
|
|
|
80
80
|
plugins: extraPlugins,
|
|
81
81
|
optimization: {
|
|
82
82
|
splitChunks: {
|
|
83
|
-
chunks: (chunk) => !helpers_1.isPolyfillsEntry(chunk.name),
|
|
83
|
+
chunks: (chunk) => !(0, helpers_1.isPolyfillsEntry)(chunk.name),
|
|
84
84
|
cacheGroups: {
|
|
85
85
|
vendors: false,
|
|
86
86
|
defaultVendors: {
|
|
@@ -41,7 +41,7 @@ function createIvyPlugin(wco, aot, tsconfig) {
|
|
|
41
41
|
const fileReplacements = {};
|
|
42
42
|
if (buildOptions.fileReplacements) {
|
|
43
43
|
for (const replacement of buildOptions.fileReplacements) {
|
|
44
|
-
fileReplacements[core_1.getSystemPath(replacement.replace)] = core_1.getSystemPath(replacement.with);
|
|
44
|
+
fileReplacements[(0, core_1.getSystemPath)(replacement.replace)] = (0, core_1.getSystemPath)(replacement.with);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
let inlineStyleFileExtension;
|
|
@@ -16,7 +16,7 @@ function getWorkerConfig(wco) {
|
|
|
16
16
|
return {};
|
|
17
17
|
}
|
|
18
18
|
return {
|
|
19
|
-
plugins: [typescript_1.getTypescriptWorkerPlugin(wco, path_1.resolve(wco.root, webWorkerTsConfig))],
|
|
19
|
+
plugins: [(0, typescript_1.getTypescriptWorkerPlugin)(wco, (0, path_1.resolve)(wco.root, webWorkerTsConfig))],
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
exports.getWorkerConfig = getWorkerConfig;
|
|
@@ -58,15 +58,15 @@ class AnyComponentStyleBudgetChecker {
|
|
|
58
58
|
size: compilation.assets[name].size(),
|
|
59
59
|
label: name,
|
|
60
60
|
}));
|
|
61
|
-
const thresholds = this.budgets.flatMap((budget) => [...bundle_calculator_1.calculateThresholds(budget)]);
|
|
61
|
+
const thresholds = this.budgets.flatMap((budget) => [...(0, bundle_calculator_1.calculateThresholds)(budget)]);
|
|
62
62
|
for (const { size, label } of componentStyles) {
|
|
63
|
-
for (const { severity, message } of bundle_calculator_1.checkThresholds(thresholds[Symbol.iterator](), size, label)) {
|
|
63
|
+
for (const { severity, message } of (0, bundle_calculator_1.checkThresholds)(thresholds[Symbol.iterator](), size, label)) {
|
|
64
64
|
switch (severity) {
|
|
65
65
|
case bundle_calculator_1.ThresholdSeverity.Warning:
|
|
66
|
-
webpack_diagnostics_1.addWarning(compilation, message);
|
|
66
|
+
(0, webpack_diagnostics_1.addWarning)(compilation, message);
|
|
67
67
|
break;
|
|
68
68
|
case bundle_calculator_1.ThresholdSeverity.Error:
|
|
69
|
-
webpack_diagnostics_1.addError(compilation, message);
|
|
69
|
+
(0, webpack_diagnostics_1.addError)(compilation, message);
|
|
70
70
|
break;
|
|
71
71
|
default:
|
|
72
72
|
assertNever(severity);
|
|
@@ -32,7 +32,7 @@ class CommonJsUsageWarnPlugin {
|
|
|
32
32
|
const { dependencies, rawRequest } = module;
|
|
33
33
|
if (!rawRequest ||
|
|
34
34
|
rawRequest.startsWith('.') ||
|
|
35
|
-
path_1.isAbsolute(rawRequest) ||
|
|
35
|
+
(0, path_1.isAbsolute)(rawRequest) ||
|
|
36
36
|
this.allowedDependencies.has(rawRequest) ||
|
|
37
37
|
this.allowedDependencies.has(this.rawRequestToPackageName(rawRequest)) ||
|
|
38
38
|
rawRequest.startsWith('@angular/common/locales/')) {
|
|
@@ -70,7 +70,7 @@ class CommonJsUsageWarnPlugin {
|
|
|
70
70
|
'For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies';
|
|
71
71
|
// Avoid showing the same warning multiple times when in 'watch' mode.
|
|
72
72
|
if (!this.shownWarnings.has(warning)) {
|
|
73
|
-
webpack_diagnostics_1.addWarning(compilation, warning);
|
|
73
|
+
(0, webpack_diagnostics_1.addWarning)(compilation, warning);
|
|
74
74
|
this.shownWarnings.add(warning);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -17,8 +17,20 @@ export interface CssOptimizerPluginOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
export declare class CssOptimizerPlugin {
|
|
19
19
|
private targets;
|
|
20
|
+
private esbuild;
|
|
20
21
|
constructor(options?: CssOptimizerPluginOptions);
|
|
21
22
|
apply(compiler: Compiler): void;
|
|
23
|
+
/**
|
|
24
|
+
* Optimizes a CSS asset using esbuild.
|
|
25
|
+
*
|
|
26
|
+
* @param input The CSS asset source content to optimize.
|
|
27
|
+
* @param name The name of the CSS asset. Used to generate source maps.
|
|
28
|
+
* @param inputMap Optionally specifies the CSS asset's original source map that will
|
|
29
|
+
* be merged with the intermediate optimized source map.
|
|
30
|
+
* @param target Optionally specifies the target browsers for the output code.
|
|
31
|
+
* @returns A promise resolving to the optimized CSS, source map, and any warnings.
|
|
32
|
+
*/
|
|
33
|
+
private optimize;
|
|
22
34
|
private addWarnings;
|
|
23
35
|
private transformSupportedBrowsersToTargets;
|
|
24
36
|
}
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.CssOptimizerPlugin = void 0;
|
|
11
|
-
const esbuild_1 = require("esbuild");
|
|
12
11
|
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
|
|
12
|
+
const esbuild_executor_1 = require("./esbuild-executor");
|
|
13
13
|
/**
|
|
14
14
|
* The name of the plugin provided to Webpack when tapping Webpack compiler hooks.
|
|
15
15
|
*/
|
|
@@ -22,6 +22,7 @@ const PLUGIN_NAME = 'angular-css-optimizer';
|
|
|
22
22
|
*/
|
|
23
23
|
class CssOptimizerPlugin {
|
|
24
24
|
constructor(options) {
|
|
25
|
+
this.esbuild = new esbuild_executor_1.EsbuildExecutor();
|
|
25
26
|
if (options === null || options === void 0 ? void 0 : options.supportedBrowsers) {
|
|
26
27
|
this.targets = this.transformSupportedBrowsersToTargets(options.supportedBrowsers);
|
|
27
28
|
}
|
|
@@ -58,20 +59,8 @@ class CssOptimizerPlugin {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
const { source, map: inputMap } = styleAssetSource.sourceAndMap();
|
|
61
|
-
let sourceMapLine;
|
|
62
|
-
if (inputMap) {
|
|
63
|
-
// esbuild will automatically remap the sourcemap if provided
|
|
64
|
-
sourceMapLine = `\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(inputMap)).toString('base64')} */`;
|
|
65
|
-
}
|
|
66
62
|
const input = typeof source === 'string' ? source : source.toString();
|
|
67
|
-
const { code, warnings, map } = await
|
|
68
|
-
loader: 'css',
|
|
69
|
-
legalComments: 'inline',
|
|
70
|
-
minify: true,
|
|
71
|
-
sourcemap: !!inputMap && 'external',
|
|
72
|
-
sourcefile: asset.name,
|
|
73
|
-
target: this.targets,
|
|
74
|
-
});
|
|
63
|
+
const { code, warnings, map } = await this.optimize(input, asset.name, inputMap, this.targets);
|
|
75
64
|
await this.addWarnings(compilation, warnings);
|
|
76
65
|
const optimizedAsset = map
|
|
77
66
|
? new SourceMapSource(code, name, map)
|
|
@@ -85,10 +74,35 @@ class CssOptimizerPlugin {
|
|
|
85
74
|
});
|
|
86
75
|
});
|
|
87
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Optimizes a CSS asset using esbuild.
|
|
79
|
+
*
|
|
80
|
+
* @param input The CSS asset source content to optimize.
|
|
81
|
+
* @param name The name of the CSS asset. Used to generate source maps.
|
|
82
|
+
* @param inputMap Optionally specifies the CSS asset's original source map that will
|
|
83
|
+
* be merged with the intermediate optimized source map.
|
|
84
|
+
* @param target Optionally specifies the target browsers for the output code.
|
|
85
|
+
* @returns A promise resolving to the optimized CSS, source map, and any warnings.
|
|
86
|
+
*/
|
|
87
|
+
optimize(input, name, inputMap, target) {
|
|
88
|
+
let sourceMapLine;
|
|
89
|
+
if (inputMap) {
|
|
90
|
+
// esbuild will automatically remap the sourcemap if provided
|
|
91
|
+
sourceMapLine = `\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(inputMap)).toString('base64')} */`;
|
|
92
|
+
}
|
|
93
|
+
return this.esbuild.transform(sourceMapLine ? input + sourceMapLine : input, {
|
|
94
|
+
loader: 'css',
|
|
95
|
+
legalComments: 'inline',
|
|
96
|
+
minify: true,
|
|
97
|
+
sourcemap: !!inputMap && 'external',
|
|
98
|
+
sourcefile: name,
|
|
99
|
+
target,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
88
102
|
async addWarnings(compilation, warnings) {
|
|
89
103
|
if (warnings.length > 0) {
|
|
90
|
-
for (const warning of await
|
|
91
|
-
webpack_diagnostics_1.addWarning(compilation, warning);
|
|
104
|
+
for (const warning of await this.esbuild.formatMessages(warnings, { kind: 'warning' })) {
|
|
105
|
+
(0, webpack_diagnostics_1.addWarning)(compilation, warning);
|
|
92
106
|
}
|
|
93
107
|
}
|
|
94
108
|
}
|
|
@@ -97,8 +111,20 @@ class CssOptimizerPlugin {
|
|
|
97
111
|
// https://esbuild.github.io/api/#target
|
|
98
112
|
const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);
|
|
99
113
|
for (const browser of supportedBrowsers) {
|
|
100
|
-
|
|
114
|
+
let [browserName, version] = browser.split(' ');
|
|
115
|
+
// browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
|
|
116
|
+
if (browserName === 'ios_saf') {
|
|
117
|
+
browserName = 'ios';
|
|
118
|
+
// browserslist also uses ranges for iOS Safari versions but only the lowest is required
|
|
119
|
+
// to perform minimum supported feature checks. esbuild also expects a single version.
|
|
120
|
+
[version] = version.split('-');
|
|
121
|
+
}
|
|
101
122
|
if (esBuildSupportedBrowsers.has(browserName)) {
|
|
123
|
+
if (browserName === 'safari' && version === 'TP') {
|
|
124
|
+
// esbuild only supports numeric versions so `TP` is converted to a high number (999) since
|
|
125
|
+
// a Technology Preview (TP) of Safari is assumed to support all currently known features.
|
|
126
|
+
version = '999';
|
|
127
|
+
}
|
|
102
128
|
transformed.push(browserName + version);
|
|
103
129
|
}
|
|
104
130
|
}
|
|
@@ -62,7 +62,7 @@ class DedupeModuleResolvePlugin {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) {
|
|
65
|
-
webpack_diagnostics_1.addWarning(compilation, `[DedupeModuleResolvePlugin]: ${resource} -> ${prevResource}`);
|
|
65
|
+
(0, webpack_diagnostics_1.addWarning)(compilation, `[DedupeModuleResolvePlugin]: ${resource} -> ${prevResource}`);
|
|
66
66
|
}
|
|
67
67
|
// Alter current request with previously resolved module.
|
|
68
68
|
const createData = result.createData;
|
|
@@ -0,0 +1,46 @@
|
|
|
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 type { FormatMessagesOptions, PartialMessage, TransformOptions, TransformResult } from 'esbuild';
|
|
9
|
+
/**
|
|
10
|
+
* Provides the ability to execute esbuild regardless of the current platform's support
|
|
11
|
+
* for using the native variant of esbuild. The native variant will be preferred (assuming
|
|
12
|
+
* the `alwaysUseWasm` constructor option is `false) due to its inherent performance advantages.
|
|
13
|
+
* At first use of esbuild, a supportability test will be automatically performed and the
|
|
14
|
+
* WASM-variant will be used if needed by the platform.
|
|
15
|
+
*/
|
|
16
|
+
export declare class EsbuildExecutor implements Pick<typeof import('esbuild'), 'transform' | 'formatMessages'> {
|
|
17
|
+
private alwaysUseWasm;
|
|
18
|
+
private esbuildTransform;
|
|
19
|
+
private esbuildFormatMessages;
|
|
20
|
+
private initialized;
|
|
21
|
+
/**
|
|
22
|
+
* Constructs an instance of the `EsbuildExecutor` class.
|
|
23
|
+
*
|
|
24
|
+
* @param alwaysUseWasm If true, the WASM-variant will be preferred and no support test will be
|
|
25
|
+
* performed; if false (default), the native variant will be preferred.
|
|
26
|
+
*/
|
|
27
|
+
constructor(alwaysUseWasm?: boolean);
|
|
28
|
+
/**
|
|
29
|
+
* Determines whether the native variant of esbuild can be used on the current platform.
|
|
30
|
+
*
|
|
31
|
+
* @returns True, if the native variant of esbuild is support; False, if the WASM variant is required.
|
|
32
|
+
*/
|
|
33
|
+
static hasNativeSupport(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Initializes the esbuild transform and format messages functions.
|
|
36
|
+
*
|
|
37
|
+
* @returns A promise that fulfills when esbuild has been loaded and available for use.
|
|
38
|
+
*/
|
|
39
|
+
private ensureEsbuild;
|
|
40
|
+
/**
|
|
41
|
+
* Transitions an executor instance to use the WASM-variant of esbuild.
|
|
42
|
+
*/
|
|
43
|
+
private useWasm;
|
|
44
|
+
transform(input: string, options?: TransformOptions): Promise<TransformResult>;
|
|
45
|
+
formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>;
|
|
46
|
+
}
|