@angular-devkit/build-angular 15.0.0-next.1 → 15.0.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 +15 -17
- package/src/babel/presets/application.d.ts +1 -2
- package/src/babel/presets/application.js +1 -4
- package/src/babel/webpack-loader.js +8 -22
- package/src/builders/app-shell/index.js +16 -8
- package/src/builders/browser/index.d.ts +1 -1
- package/src/builders/browser/index.js +4 -16
- package/src/builders/browser/schema.d.ts +6 -2
- package/src/builders/browser/schema.json +18 -4
- package/src/builders/browser-esbuild/compiler-plugin.d.ts +1 -0
- package/src/builders/browser-esbuild/compiler-plugin.js +20 -17
- package/src/builders/browser-esbuild/experimental-warnings.js +0 -1
- package/src/builders/browser-esbuild/index.js +18 -5
- package/src/builders/browser-esbuild/options.js +6 -1
- package/src/builders/browser-esbuild/schema.d.ts +8 -6
- package/src/builders/browser-esbuild/schema.json +29 -34
- package/src/builders/browser-esbuild/stylesheets.d.ts +1 -0
- package/src/builders/browser-esbuild/stylesheets.js +1 -0
- package/src/builders/extract-i18n/index.js +1 -1
- package/src/builders/karma/find-tests-plugin.d.ts +19 -0
- package/src/builders/karma/{find-tests.js → find-tests-plugin.js} +49 -5
- package/src/builders/karma/index.js +40 -38
- package/src/builders/karma/schema.d.ts +7 -3
- package/src/builders/karma/schema.json +20 -5
- package/src/builders/server/index.d.ts +1 -1
- package/src/builders/server/index.js +42 -10
- package/src/builders/server/platform-server-exports-loader.d.ts +13 -0
- package/src/builders/server/platform-server-exports-loader.js +24 -0
- package/src/builders/server/schema.d.ts +0 -5
- package/src/builders/server/schema.json +0 -5
- package/src/sass/sass-service-legacy.d.ts +51 -0
- package/src/sass/sass-service-legacy.js +175 -0
- package/src/sass/sass-service.d.ts +6 -9
- package/src/sass/sass-service.js +69 -52
- package/src/{builders/karma/find-tests.d.ts → sass/worker-legacy.d.ts} +1 -1
- package/src/sass/worker-legacy.js +44 -0
- package/src/sass/worker.js +64 -14
- package/src/utils/build-options.d.ts +2 -4
- package/src/utils/environment-options.d.ts +1 -0
- package/src/utils/environment-options.js +11 -1
- package/src/utils/esbuild-targets.d.ts +12 -0
- package/src/utils/esbuild-targets.js +39 -0
- package/src/utils/i18n-inlining.d.ts +1 -1
- package/src/utils/i18n-inlining.js +3 -4
- package/src/utils/normalize-builder-schema.d.ts +3 -2
- package/src/utils/normalize-builder-schema.js +5 -4
- package/src/utils/normalize-polyfills.d.ts +8 -0
- package/src/utils/normalize-polyfills.js +24 -0
- package/src/utils/process-bundle.d.ts +0 -1
- package/src/utils/process-bundle.js +29 -57
- package/src/utils/supported-browsers.d.ts +2 -1
- package/src/utils/supported-browsers.js +18 -2
- package/src/utils/webpack-browser-config.d.ts +0 -2
- package/src/utils/webpack-browser-config.js +2 -8
- package/src/utils/webpack-diagnostics.d.ts +1 -1
- package/src/utils/webpack-diagnostics.js +2 -3
- package/src/webpack/configs/common.js +37 -24
- package/src/webpack/configs/dev-server.js +1 -1
- package/src/webpack/configs/styles.js +63 -80
- package/src/webpack/plugins/any-component-style-budget-checker.js +1 -1
- package/src/webpack/plugins/css-optimizer-plugin.d.ts +0 -1
- package/src/webpack/plugins/css-optimizer-plugin.js +3 -26
- package/src/webpack/plugins/hmr/hmr-loader.d.ts +1 -1
- package/src/webpack/plugins/hmr/hmr-loader.js +2 -5
- package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +4 -6
- package/src/webpack/plugins/javascript-optimizer-plugin.js +7 -16
- package/src/webpack/plugins/javascript-optimizer-worker.d.ts +3 -2
- package/src/webpack/plugins/javascript-optimizer-worker.js +21 -46
- package/src/webpack/plugins/karma/karma.js +4 -5
- package/src/webpack/plugins/transfer-size-plugin.js +2 -1
- package/src/webpack/plugins/typescript.js +14 -25
- package/src/webpack/utils/helpers.d.ts +0 -3
- package/src/webpack/utils/helpers.js +1 -36
- package/src/webpack/plugins/single-test-transform.d.ts +0 -27
- package/src/webpack/plugins/single-test-transform.js +0 -44
|
@@ -37,8 +37,9 @@ exports.getStylesConfig = exports.resolveGlobalStyles = void 0;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
-
const webpack_1 = require("webpack");
|
|
41
40
|
const sass_service_1 = require("../../sass/sass-service");
|
|
41
|
+
const sass_service_legacy_1 = require("../../sass/sass-service-legacy");
|
|
42
|
+
const environment_options_1 = require("../../utils/environment-options");
|
|
42
43
|
const plugins_1 = require("../plugins");
|
|
43
44
|
const css_optimizer_plugin_1 = require("../plugins/css-optimizer-plugin");
|
|
44
45
|
const helpers_1 = require("../utils/helpers");
|
|
@@ -83,7 +84,7 @@ exports.resolveGlobalStyles = resolveGlobalStyles;
|
|
|
83
84
|
// eslint-disable-next-line max-lines-per-function
|
|
84
85
|
function getStylesConfig(wco) {
|
|
85
86
|
var _a, _b, _c;
|
|
86
|
-
const { root, buildOptions } = wco;
|
|
87
|
+
const { root, projectRoot, buildOptions } = wco;
|
|
87
88
|
const extraPlugins = [];
|
|
88
89
|
extraPlugins.push(new plugins_1.AnyComponentStyleBudgetChecker(buildOptions.budgets));
|
|
89
90
|
const cssSourceMap = buildOptions.sourceMap.styles;
|
|
@@ -97,23 +98,14 @@ function getStylesConfig(wco) {
|
|
|
97
98
|
// Add plugin to remove hashes from lazy styles.
|
|
98
99
|
extraPlugins.push(new plugins_1.RemoveHashPlugin({ chunkNames: noInjectNames, hashFormat }));
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
const sassImplementation = new sass_service_1.SassWorkerImplementation();
|
|
105
|
-
const sassTildeUsageMessage = new Set();
|
|
101
|
+
const sassImplementation = environment_options_1.useLegacySass
|
|
102
|
+
? new sass_service_legacy_1.SassLegacyWorkerImplementation()
|
|
103
|
+
: new sass_service_1.SassWorkerImplementation();
|
|
106
104
|
extraPlugins.push({
|
|
107
105
|
apply(compiler) {
|
|
108
106
|
compiler.hooks.shutdown.tap('sass-worker', () => {
|
|
109
107
|
sassImplementation.close();
|
|
110
108
|
});
|
|
111
|
-
compiler.hooks.afterCompile.tap('sass-worker', (compilation) => {
|
|
112
|
-
for (const message of sassTildeUsageMessage) {
|
|
113
|
-
compilation.warnings.push(new webpack_1.WebpackError(message));
|
|
114
|
-
}
|
|
115
|
-
sassTildeUsageMessage.clear();
|
|
116
|
-
});
|
|
117
109
|
},
|
|
118
110
|
});
|
|
119
111
|
const assetNameTemplate = (0, helpers_1.assetNameTemplateFactory)(hashFormat);
|
|
@@ -151,7 +143,6 @@ function getStylesConfig(wco) {
|
|
|
151
143
|
: undefined,
|
|
152
144
|
plugins: [
|
|
153
145
|
postcssImports({
|
|
154
|
-
resolve: (url) => (url.startsWith('~') ? url.slice(1) : url),
|
|
155
146
|
load: (filename) => {
|
|
156
147
|
return new Promise((resolve, reject) => {
|
|
157
148
|
loader.fs.readFile(filename, (err, data) => {
|
|
@@ -247,30 +238,7 @@ function getStylesConfig(wco) {
|
|
|
247
238
|
},
|
|
248
239
|
{
|
|
249
240
|
loader: require.resolve('sass-loader'),
|
|
250
|
-
options:
|
|
251
|
-
implementation: sassImplementation,
|
|
252
|
-
sourceMap: true,
|
|
253
|
-
sassOptions: {
|
|
254
|
-
importer: (url, from) => {
|
|
255
|
-
if (url.charAt(0) === '~') {
|
|
256
|
-
sassTildeUsageMessage.add(`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is deprecated.`);
|
|
257
|
-
}
|
|
258
|
-
return null;
|
|
259
|
-
},
|
|
260
|
-
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
|
|
261
|
-
fiber: false,
|
|
262
|
-
// bootstrap-sass requires a minimum precision of 8
|
|
263
|
-
precision: 8,
|
|
264
|
-
includePaths,
|
|
265
|
-
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
|
|
266
|
-
// Ex: /* autoprefixer grid: autoplace */
|
|
267
|
-
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
|
|
268
|
-
outputStyle: 'expanded',
|
|
269
|
-
// Silences compiler warnings from 3rd party stylesheets
|
|
270
|
-
quietDeps: !buildOptions.verbose,
|
|
271
|
-
verbose: buildOptions.verbose,
|
|
272
|
-
},
|
|
273
|
-
},
|
|
241
|
+
options: getSassLoaderOptions(root, projectRoot, sassImplementation, includePaths, false, !buildOptions.verbose),
|
|
274
242
|
},
|
|
275
243
|
],
|
|
276
244
|
},
|
|
@@ -285,31 +253,7 @@ function getStylesConfig(wco) {
|
|
|
285
253
|
},
|
|
286
254
|
{
|
|
287
255
|
loader: require.resolve('sass-loader'),
|
|
288
|
-
options:
|
|
289
|
-
implementation: sassImplementation,
|
|
290
|
-
sourceMap: true,
|
|
291
|
-
sassOptions: {
|
|
292
|
-
importer: (url, from) => {
|
|
293
|
-
if (url.charAt(0) === '~') {
|
|
294
|
-
sassTildeUsageMessage.add(`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is deprecated.`);
|
|
295
|
-
}
|
|
296
|
-
return null;
|
|
297
|
-
},
|
|
298
|
-
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
|
|
299
|
-
fiber: false,
|
|
300
|
-
indentedSyntax: true,
|
|
301
|
-
// bootstrap-sass requires a minimum precision of 8
|
|
302
|
-
precision: 8,
|
|
303
|
-
includePaths,
|
|
304
|
-
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
|
|
305
|
-
// Ex: /* autoprefixer grid: autoplace */
|
|
306
|
-
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
|
|
307
|
-
outputStyle: 'expanded',
|
|
308
|
-
// Silences compiler warnings from 3rd party stylesheets
|
|
309
|
-
quietDeps: !buildOptions.verbose,
|
|
310
|
-
verbose: buildOptions.verbose,
|
|
311
|
-
},
|
|
312
|
-
},
|
|
256
|
+
options: getSassLoaderOptions(root, projectRoot, sassImplementation, includePaths, true, !buildOptions.verbose),
|
|
313
257
|
},
|
|
314
258
|
],
|
|
315
259
|
},
|
|
@@ -329,22 +273,6 @@ function getStylesConfig(wco) {
|
|
|
329
273
|
},
|
|
330
274
|
],
|
|
331
275
|
},
|
|
332
|
-
{
|
|
333
|
-
extensions: ['styl'],
|
|
334
|
-
use: [
|
|
335
|
-
{
|
|
336
|
-
loader: require.resolve('stylus-loader'),
|
|
337
|
-
options: {
|
|
338
|
-
sourceMap: cssSourceMap,
|
|
339
|
-
stylusOptions: {
|
|
340
|
-
compress: false,
|
|
341
|
-
sourceMap: { comment: false },
|
|
342
|
-
paths: includePaths,
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
],
|
|
347
|
-
},
|
|
348
276
|
];
|
|
349
277
|
return {
|
|
350
278
|
entry: entryPoints,
|
|
@@ -402,3 +330,58 @@ function getTailwindConfigPath({ projectRoot, root }) {
|
|
|
402
330
|
}
|
|
403
331
|
return undefined;
|
|
404
332
|
}
|
|
333
|
+
function getSassLoaderOptions(root, projectRoot, implementation, includePaths, indentedSyntax, verbose) {
|
|
334
|
+
return implementation instanceof sass_service_1.SassWorkerImplementation
|
|
335
|
+
? {
|
|
336
|
+
sourceMap: true,
|
|
337
|
+
api: 'modern',
|
|
338
|
+
implementation,
|
|
339
|
+
// Webpack importer is only implemented in the legacy API.
|
|
340
|
+
// See: https://github.com/webpack-contrib/sass-loader/blob/997f3eb41d86dd00d5fa49c395a1aeb41573108c/src/utils.js#L642-L651
|
|
341
|
+
webpackImporter: false,
|
|
342
|
+
sassOptions: {
|
|
343
|
+
loadPaths: [
|
|
344
|
+
...includePaths,
|
|
345
|
+
// Needed to resolve node packages and retain the same behaviour of with the legacy API as sass-loader resolves
|
|
346
|
+
// scss also from the cwd and project root.
|
|
347
|
+
// See: https://github.com/webpack-contrib/sass-loader/blob/997f3eb41d86dd00d5fa49c395a1aeb41573108c/src/utils.js#L307
|
|
348
|
+
projectRoot,
|
|
349
|
+
path.join(root, 'node_modules'),
|
|
350
|
+
],
|
|
351
|
+
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
|
|
352
|
+
// Ex: /* autoprefixer grid: autoplace */
|
|
353
|
+
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
|
|
354
|
+
style: 'expanded',
|
|
355
|
+
// Silences compiler warnings from 3rd party stylesheets
|
|
356
|
+
quietDeps: !verbose,
|
|
357
|
+
verbose,
|
|
358
|
+
syntax: indentedSyntax ? 'indented' : 'scss',
|
|
359
|
+
},
|
|
360
|
+
}
|
|
361
|
+
: {
|
|
362
|
+
sourceMap: true,
|
|
363
|
+
api: 'legacy',
|
|
364
|
+
implementation,
|
|
365
|
+
sassOptions: {
|
|
366
|
+
importer: (url, from) => {
|
|
367
|
+
if (url.charAt(0) === '~') {
|
|
368
|
+
throw new Error(`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is no longer supported.`);
|
|
369
|
+
}
|
|
370
|
+
return null;
|
|
371
|
+
},
|
|
372
|
+
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
|
|
373
|
+
fiber: false,
|
|
374
|
+
indentedSyntax,
|
|
375
|
+
// bootstrap-sass requires a minimum precision of 8
|
|
376
|
+
precision: 8,
|
|
377
|
+
includePaths,
|
|
378
|
+
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
|
|
379
|
+
// Ex: /* autoprefixer grid: autoplace */
|
|
380
|
+
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
|
|
381
|
+
outputStyle: 'expanded',
|
|
382
|
+
// Silences compiler warnings from 3rd party stylesheets
|
|
383
|
+
quietDeps: !verbose,
|
|
384
|
+
verbose,
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
@@ -59,7 +59,7 @@ class AnyComponentStyleBudgetChecker {
|
|
|
59
59
|
if (!compilation.compiler.parentCompilation) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
const cssExtensions = ['.css', '.scss', '.less', '.
|
|
62
|
+
const cssExtensions = ['.css', '.scss', '.less', '.sass'];
|
|
63
63
|
const componentStyles = Object.keys(compilation.assets)
|
|
64
64
|
.filter((name) => cssExtensions.includes(path.extname(name)))
|
|
65
65
|
.map((name) => ({
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.CssOptimizerPlugin = void 0;
|
|
11
|
+
const esbuild_targets_1 = require("../../utils/esbuild-targets");
|
|
11
12
|
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
|
|
12
13
|
const esbuild_executor_1 = require("./esbuild-executor");
|
|
13
14
|
/**
|
|
@@ -24,7 +25,7 @@ class CssOptimizerPlugin {
|
|
|
24
25
|
constructor(options) {
|
|
25
26
|
this.esbuild = new esbuild_executor_1.EsbuildExecutor();
|
|
26
27
|
if (options === null || options === void 0 ? void 0 : options.supportedBrowsers) {
|
|
27
|
-
this.targets =
|
|
28
|
+
this.targets = (0, esbuild_targets_1.transformSupportedBrowsersToTargets)(options.supportedBrowsers);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
apply(compiler) {
|
|
@@ -38,7 +39,7 @@ class CssOptimizerPlugin {
|
|
|
38
39
|
const cache = compilation.options.cache && compilation.getCache(PLUGIN_NAME);
|
|
39
40
|
logger.time('optimize css assets');
|
|
40
41
|
for (const assetName of Object.keys(compilationAssets)) {
|
|
41
|
-
if (!/\.(?:css|scss|sass|less
|
|
42
|
+
if (!/\.(?:css|scss|sass|less)$/.test(assetName)) {
|
|
42
43
|
continue;
|
|
43
44
|
}
|
|
44
45
|
const asset = compilation.getAsset(assetName);
|
|
@@ -117,29 +118,5 @@ class CssOptimizerPlugin {
|
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
|
-
transformSupportedBrowsersToTargets(supportedBrowsers) {
|
|
121
|
-
const transformed = [];
|
|
122
|
-
// https://esbuild.github.io/api/#target
|
|
123
|
-
const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);
|
|
124
|
-
for (const browser of supportedBrowsers) {
|
|
125
|
-
let [browserName, version] = browser.split(' ');
|
|
126
|
-
// browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
|
|
127
|
-
if (browserName === 'ios_saf') {
|
|
128
|
-
browserName = 'ios';
|
|
129
|
-
}
|
|
130
|
-
// browserslist uses ranges `15.2-15.3` versions but only the lowest is required
|
|
131
|
-
// to perform minimum supported feature checks. esbuild also expects a single version.
|
|
132
|
-
[version] = version.split('-');
|
|
133
|
-
if (esBuildSupportedBrowsers.has(browserName)) {
|
|
134
|
-
if (browserName === 'safari' && version === 'TP') {
|
|
135
|
-
// esbuild only supports numeric versions so `TP` is converted to a high number (999) since
|
|
136
|
-
// a Technology Preview (TP) of Safari is assumed to support all currently known features.
|
|
137
|
-
version = '999';
|
|
138
|
-
}
|
|
139
|
-
transformed.push(browserName + version);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return transformed.length ? transformed : undefined;
|
|
143
|
-
}
|
|
144
121
|
}
|
|
145
122
|
exports.CssOptimizerPlugin = CssOptimizerPlugin;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
export declare const HmrLoader: string;
|
|
9
|
-
export default function (this:
|
|
9
|
+
export default function localizeExtractLoader(this: import('webpack').LoaderContext<{}>, content: string, map: Parameters<import('webpack').LoaderDefinitionFunction>[1]): void;
|
|
@@ -11,10 +11,7 @@ exports.HmrLoader = void 0;
|
|
|
11
11
|
const path_1 = require("path");
|
|
12
12
|
exports.HmrLoader = __filename;
|
|
13
13
|
const hmrAcceptPath = (0, path_1.join)(__dirname, './hmr-accept.js').replace(/\\/g, '/');
|
|
14
|
-
function
|
|
15
|
-
// Source map types are broken in the webpack type definitions
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
map) {
|
|
14
|
+
function localizeExtractLoader(content, map) {
|
|
18
15
|
const source = `${content}
|
|
19
16
|
|
|
20
17
|
// HMR Accept Code
|
|
@@ -24,4 +21,4 @@ map) {
|
|
|
24
21
|
this.callback(null, source, map);
|
|
25
22
|
return;
|
|
26
23
|
}
|
|
27
|
-
exports.default =
|
|
24
|
+
exports.default = localizeExtractLoader;
|
|
@@ -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
|
-
import { ScriptTarget } from 'typescript';
|
|
9
8
|
import type { Compiler } from 'webpack';
|
|
10
9
|
/**
|
|
11
10
|
* The options used to configure the {@link JavaScriptOptimizerPlugin}.
|
|
@@ -29,11 +28,9 @@ export interface JavaScriptOptimizerOptions {
|
|
|
29
28
|
*/
|
|
30
29
|
sourcemap?: boolean;
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
33
|
-
* The optimizer will not adjust the output code with features present in newer
|
|
34
|
-
* ECMAScript versions.
|
|
31
|
+
* A list of supported browsers that is used for output code.
|
|
35
32
|
*/
|
|
36
|
-
|
|
33
|
+
supportedBrowsers?: string[];
|
|
37
34
|
/**
|
|
38
35
|
* Enables the retention of identifier names and ensures that function and class names are
|
|
39
36
|
* present in the output code.
|
|
@@ -61,7 +58,8 @@ export interface JavaScriptOptimizerOptions {
|
|
|
61
58
|
* optimizations not yet implemented by `esbuild`.
|
|
62
59
|
*/
|
|
63
60
|
export declare class JavaScriptOptimizerPlugin {
|
|
64
|
-
options
|
|
61
|
+
private options;
|
|
62
|
+
private targets;
|
|
65
63
|
constructor(options: JavaScriptOptimizerOptions);
|
|
66
64
|
apply(compiler: Compiler): void;
|
|
67
65
|
}
|
|
@@ -12,8 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.JavaScriptOptimizerPlugin = void 0;
|
|
14
14
|
const piscina_1 = __importDefault(require("piscina"));
|
|
15
|
-
const typescript_1 = require("typescript");
|
|
16
15
|
const environment_options_1 = require("../../utils/environment-options");
|
|
16
|
+
const esbuild_targets_1 = require("../../utils/esbuild-targets");
|
|
17
|
+
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
|
|
17
18
|
const esbuild_executor_1 = require("./esbuild-executor");
|
|
18
19
|
/**
|
|
19
20
|
* The maximum number of Workers that will be created to execute optimize tasks.
|
|
@@ -34,6 +35,9 @@ const PLUGIN_NAME = 'angular-javascript-optimizer';
|
|
|
34
35
|
class JavaScriptOptimizerPlugin {
|
|
35
36
|
constructor(options) {
|
|
36
37
|
this.options = options;
|
|
38
|
+
if (options.supportedBrowsers) {
|
|
39
|
+
this.targets = (0, esbuild_targets_1.transformSupportedBrowsersToTargets)(options.supportedBrowsers);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
apply(compiler) {
|
|
39
43
|
const { OriginalSource, SourceMapSource } = compiler.webpack.sources;
|
|
@@ -90,25 +94,13 @@ class JavaScriptOptimizerPlugin {
|
|
|
90
94
|
define[key] = String(value);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
|
-
let target = 2017;
|
|
94
|
-
if (this.options.target) {
|
|
95
|
-
if (this.options.target <= typescript_1.ScriptTarget.ES5) {
|
|
96
|
-
target = 5;
|
|
97
|
-
}
|
|
98
|
-
else if (this.options.target === typescript_1.ScriptTarget.ESNext) {
|
|
99
|
-
target = 'next';
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
target = Number(typescript_1.ScriptTarget[this.options.target].slice(2));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
97
|
// Setup the options used by all worker tasks
|
|
106
98
|
const optimizeOptions = {
|
|
107
99
|
sourcemap: this.options.sourcemap,
|
|
108
100
|
define,
|
|
109
101
|
keepNames: this.options.keepNames,
|
|
110
102
|
keepIdentifierNames: this.options.keepIdentifierNames,
|
|
111
|
-
target,
|
|
103
|
+
target: this.targets,
|
|
112
104
|
removeLicenses: this.options.removeLicenses,
|
|
113
105
|
advanced: this.options.advanced,
|
|
114
106
|
// Perform a single native esbuild support check.
|
|
@@ -151,8 +143,7 @@ class JavaScriptOptimizerPlugin {
|
|
|
151
143
|
source: optimizedAsset,
|
|
152
144
|
});
|
|
153
145
|
}, (error) => {
|
|
154
|
-
|
|
155
|
-
compilation.errors.push(optimizationError);
|
|
146
|
+
(0, webpack_diagnostics_1.addError)(compilation, `Optimization error [${name}]: ${error.stack || error.message}`);
|
|
156
147
|
}));
|
|
157
148
|
}
|
|
158
149
|
await Promise.all(tasks);
|
|
@@ -39,9 +39,10 @@ export interface OptimizeRequestOptions {
|
|
|
39
39
|
*/
|
|
40
40
|
sourcemap?: boolean;
|
|
41
41
|
/**
|
|
42
|
-
* Specifies the
|
|
42
|
+
* Specifies the list of supported esbuild targets.
|
|
43
|
+
* @see: https://esbuild.github.io/api/#target
|
|
43
44
|
*/
|
|
44
|
-
target
|
|
45
|
+
target?: string[];
|
|
45
46
|
/**
|
|
46
47
|
* Controls whether esbuild should only use the WASM-variant instead of trying to
|
|
47
48
|
* use the native variant. Some platforms may not support the native-variant and
|
|
@@ -26,9 +26,7 @@ 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,
|
|
30
|
-
// Terser only supports up to ES2020.
|
|
31
|
-
options.target === 'next' ? 2020 : options.target, options.advanced);
|
|
29
|
+
const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap, options.advanced);
|
|
32
30
|
// Merge intermediate sourcemaps with input sourcemap if enabled
|
|
33
31
|
let fullSourcemap;
|
|
34
32
|
if (options.sourcemap) {
|
|
@@ -56,49 +54,26 @@ exports.default = default_1;
|
|
|
56
54
|
* @returns A promise that resolves with the optimized code, source map, and any warnings.
|
|
57
55
|
*/
|
|
58
56
|
async function optimizeWithEsbuild(content, name, options) {
|
|
59
|
-
var _a;
|
|
60
57
|
if (!esbuild) {
|
|
61
58
|
esbuild = new esbuild_executor_1.EsbuildExecutor(options.alwaysUseWasm);
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
target: `es${options.target}`,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
const failure = error;
|
|
85
|
-
// If esbuild fails with only ES5 support errors, fallback to just terser.
|
|
86
|
-
// This will only happen if ES5 is the output target and a global script contains ES2015+ syntax.
|
|
87
|
-
// In that case, the global script is technically already invalid for the target environment but
|
|
88
|
-
// this is and has been considered a configuration issue. Global scripts must be compatible with
|
|
89
|
-
// the target environment.
|
|
90
|
-
if ((_a = failure.errors) === null || _a === void 0 ? void 0 : _a.every((error) => error.text.includes('to the configured target environment ("es5") is not supported yet'))) {
|
|
91
|
-
result = {
|
|
92
|
-
code: content,
|
|
93
|
-
map: '',
|
|
94
|
-
warnings: [],
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
60
|
+
return esbuild.transform(content, {
|
|
61
|
+
minifyIdentifiers: !options.keepIdentifierNames,
|
|
62
|
+
minifySyntax: true,
|
|
63
|
+
// NOTE: Disabling whitespace ensures unused pure annotations are kept
|
|
64
|
+
minifyWhitespace: false,
|
|
65
|
+
pure: ['forwardRef'],
|
|
66
|
+
legalComments: options.removeLicenses ? 'none' : 'inline',
|
|
67
|
+
sourcefile: name,
|
|
68
|
+
sourcemap: options.sourcemap && 'external',
|
|
69
|
+
define: options.define,
|
|
70
|
+
// This option should always be disabled for browser builds as we don't rely on `.name`
|
|
71
|
+
// and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
|
|
72
|
+
// We enable `keepNames` only for server builds as Domino relies on `.name`.
|
|
73
|
+
// Once we no longer rely on Domino for SSR we should be able to remove this.
|
|
74
|
+
keepNames: options.keepNames,
|
|
75
|
+
target: options.target,
|
|
76
|
+
});
|
|
102
77
|
}
|
|
103
78
|
/**
|
|
104
79
|
* Optimizes a JavaScript asset using terser.
|
|
@@ -106,17 +81,17 @@ async function optimizeWithEsbuild(content, name, options) {
|
|
|
106
81
|
* @param name The name of the JavaScript asset. Used to generate source maps.
|
|
107
82
|
* @param code The JavaScript asset source content to optimize.
|
|
108
83
|
* @param sourcemaps If true, generate an output source map for the optimized code.
|
|
109
|
-
* @param target Specifies the target ECMAScript version for the output code.
|
|
110
84
|
* @param advanced Controls advanced optimizations.
|
|
111
85
|
* @returns A promise that resolves with the optimized code and source map.
|
|
112
86
|
*/
|
|
113
|
-
async function optimizeWithTerser(name, code, sourcemaps,
|
|
87
|
+
async function optimizeWithTerser(name, code, sourcemaps, advanced) {
|
|
114
88
|
const result = await (0, terser_1.minify)({ [name]: code }, {
|
|
115
89
|
compress: {
|
|
116
90
|
passes: advanced ? 2 : 1,
|
|
117
91
|
pure_getters: advanced,
|
|
118
92
|
},
|
|
119
|
-
|
|
93
|
+
// terser only supports up to ES2020
|
|
94
|
+
ecma: 2020,
|
|
120
95
|
// esbuild in the first pass is used to minify identifiers instead of mangle here
|
|
121
96
|
mangle: false,
|
|
122
97
|
// esbuild in the first pass is used to minify function names
|
|
@@ -109,7 +109,6 @@ const init = (config, emitter) => {
|
|
|
109
109
|
webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
|
|
110
110
|
webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;
|
|
111
111
|
const compiler = (0, webpack_1.default)(webpackConfig, (error, stats) => {
|
|
112
|
-
var _a;
|
|
113
112
|
if (error) {
|
|
114
113
|
throw error;
|
|
115
114
|
}
|
|
@@ -122,10 +121,10 @@ const init = (config, emitter) => {
|
|
|
122
121
|
warnings: true,
|
|
123
122
|
});
|
|
124
123
|
logger.error((0, stats_1.statsErrorsToString)(statsJson, { colors: true }));
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
124
|
+
if (config.singleRun) {
|
|
125
|
+
// Notify potential listeners of the compile error.
|
|
126
|
+
emitter.emit('load_error');
|
|
127
|
+
}
|
|
129
128
|
// Finish Karma run early in case of compilation error.
|
|
130
129
|
emitter.emit('run_complete', [], { exitCode: 1 });
|
|
131
130
|
// Emit a failure build event if there are compilation errors.
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.TransferSizePlugin = void 0;
|
|
11
11
|
const util_1 = require("util");
|
|
12
12
|
const zlib_1 = require("zlib");
|
|
13
|
+
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
|
|
13
14
|
const brotliCompressAsync = (0, util_1.promisify)(zlib_1.brotliCompress);
|
|
14
15
|
const PLUGIN_NAME = 'angular-transfer-size-estimator';
|
|
15
16
|
class TransferSizePlugin {
|
|
@@ -37,7 +38,7 @@ class TransferSizePlugin {
|
|
|
37
38
|
}));
|
|
38
39
|
})
|
|
39
40
|
.catch((error) => {
|
|
40
|
-
|
|
41
|
+
(0, webpack_diagnostics_1.addWarning)(compilation, `Unable to calculate estimated transfer size for '${assetName}'. Reason: ${error.message}`);
|
|
41
42
|
}));
|
|
42
43
|
}
|
|
43
44
|
await Promise.all(actions);
|
|
@@ -11,52 +11,41 @@ exports.createIvyPlugin = void 0;
|
|
|
11
11
|
const webpack_1 = require("@ngtools/webpack");
|
|
12
12
|
const typescript_1 = require("typescript");
|
|
13
13
|
function createIvyPlugin(wco, aot, tsconfig) {
|
|
14
|
-
|
|
14
|
+
var _a, _b;
|
|
15
|
+
var _c;
|
|
16
|
+
const { buildOptions, tsConfig } = wco;
|
|
15
17
|
const optimize = buildOptions.optimization.scripts;
|
|
16
18
|
const compilerOptions = {
|
|
17
19
|
sourceMap: buildOptions.sourceMap.scripts,
|
|
18
20
|
declaration: false,
|
|
19
21
|
declarationMap: false,
|
|
20
22
|
};
|
|
23
|
+
if (tsConfig.options.target === undefined || tsConfig.options.target < typescript_1.ScriptTarget.ES2022) {
|
|
24
|
+
tsConfig.options.target = typescript_1.ScriptTarget.ES2022;
|
|
25
|
+
// If 'useDefineForClassFields' is already defined in the users project leave the value as is.
|
|
26
|
+
// Otherwise fallback to false due to https://github.com/microsoft/TypeScript/issues/45995
|
|
27
|
+
// which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
|
|
28
|
+
(_a = (_c = tsConfig.options).useDefineForClassFields) !== null && _a !== void 0 ? _a : (_c.useDefineForClassFields = false);
|
|
29
|
+
wco.logger.warn('TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and ' +
|
|
30
|
+
'"false" respectively by the Angular CLI. To control ECMA version and features use the Browerslist configuration. ' +
|
|
31
|
+
'For more information, see https://github.com/browserslist/browserslist');
|
|
32
|
+
}
|
|
21
33
|
if (buildOptions.preserveSymlinks !== undefined) {
|
|
22
34
|
compilerOptions.preserveSymlinks = buildOptions.preserveSymlinks;
|
|
23
35
|
}
|
|
24
|
-
// Outputting ES2015 from TypeScript is the required minimum for the build optimizer passes.
|
|
25
|
-
// Downleveling to ES5 will occur after the build optimizer passes via babel which is the same
|
|
26
|
-
// as for third-party libraries. This greatly reduces the complexity of static analysis.
|
|
27
|
-
if (wco.scriptTarget < typescript_1.ScriptTarget.ES2015) {
|
|
28
|
-
compilerOptions.target = typescript_1.ScriptTarget.ES2015;
|
|
29
|
-
wco.logger.warn('DEPRECATED: ES5 output is deprecated. Please update TypeScript `target` compiler option to ES2015 or later.');
|
|
30
|
-
}
|
|
31
36
|
const fileReplacements = {};
|
|
32
37
|
if (buildOptions.fileReplacements) {
|
|
33
38
|
for (const replacement of buildOptions.fileReplacements) {
|
|
34
39
|
fileReplacements[replacement.replace] = replacement.with;
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
let inlineStyleFileExtension;
|
|
38
|
-
switch (buildOptions.inlineStyleLanguage) {
|
|
39
|
-
case 'less':
|
|
40
|
-
inlineStyleFileExtension = 'less';
|
|
41
|
-
break;
|
|
42
|
-
case 'sass':
|
|
43
|
-
inlineStyleFileExtension = 'sass';
|
|
44
|
-
break;
|
|
45
|
-
case 'scss':
|
|
46
|
-
inlineStyleFileExtension = 'scss';
|
|
47
|
-
break;
|
|
48
|
-
case 'css':
|
|
49
|
-
default:
|
|
50
|
-
inlineStyleFileExtension = 'css';
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
42
|
return new webpack_1.AngularWebpackPlugin({
|
|
54
43
|
tsconfig,
|
|
55
44
|
compilerOptions,
|
|
56
45
|
fileReplacements,
|
|
57
46
|
jitMode: !aot,
|
|
58
47
|
emitNgModuleScope: !optimize,
|
|
59
|
-
inlineStyleFileExtension,
|
|
48
|
+
inlineStyleFileExtension: (_b = buildOptions.inlineStyleLanguage) !== null && _b !== void 0 ? _b : 'css',
|
|
60
49
|
});
|
|
61
50
|
}
|
|
62
51
|
exports.createIvyPlugin = createIvyPlugin;
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import type { ObjectPattern } from 'copy-webpack-plugin';
|
|
9
|
-
import { ScriptTarget } from 'typescript';
|
|
10
9
|
import type { Configuration, WebpackOptionsNormalized } from 'webpack';
|
|
11
10
|
import { AssetPatternClass, OutputHashing, ScriptElement, StyleElement } from '../../builders/browser/schema';
|
|
12
11
|
import { WebpackConfigOptions } from '../../utils/build-options';
|
|
@@ -29,6 +28,4 @@ export declare function globalScriptsByBundleName(root: string, scripts: ScriptE
|
|
|
29
28
|
paths: string[];
|
|
30
29
|
}[];
|
|
31
30
|
export declare function assetPatterns(root: string, assets: AssetPatternClass[]): ObjectPattern[];
|
|
32
|
-
export declare function externalizePackages(context: string, request: string | undefined, callback: (error?: Error, result?: string) => void): void;
|
|
33
31
|
export declare function getStatsOptions(verbose?: boolean): WebpackStatsOptions;
|
|
34
|
-
export declare function getMainFieldsAndConditionNames(target: ScriptTarget, platformServer: boolean): Pick<WebpackOptionsNormalized['resolve'], 'mainFields' | 'conditionNames'>;
|