Skip to content

Commit 36be8cd

Browse files
committed
feat(@angular-devkit/build-angular): warn when target greater es2015
When using differential loading with targets ES5 and ES2016+, the browser with ESM support will pick `script[type="module"]` scripts even without supporting ES2016+ syntax. We want to warn users in this case.
1 parent a197615 commit 36be8cd

File tree

1 file changed

+18
-2
lines changed
  • packages/angular_devkit/build_angular/src/browser

1 file changed

+18
-2
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import {
1818
logging,
1919
normalize,
2020
resolve,
21+
tags,
2122
virtualFs,
2223
} from '@angular-devkit/core';
2324
import { NodeJsSyncHost } from '@angular-devkit/core/node';
2425
import * as fs from 'fs';
2526
import * as path from 'path';
26-
import { concat, from, of, zip } from 'rxjs';
27+
import { from, of } from 'rxjs';
2728
import { bufferCount, catchError, concatMap, map, mergeScan, switchMap } from 'rxjs/operators';
29+
import * as ts from 'typescript';
2830
import * as webpack from 'webpack';
2931
import { NgBuildAnalyticsPlugin } from '../../plugins/webpack/analytics';
3032
import { WebpackConfigOptions } from '../angular-cli-files/models/build-options';
@@ -38,14 +40,15 @@ import {
3840
getWorkerConfig,
3941
} from '../angular-cli-files/models/webpack-configs';
4042
import { writeIndexHtml } from '../angular-cli-files/utilities/index-file/write-index-html';
43+
import { readTsconfig } from '../angular-cli-files/utilities/read-tsconfig';
4144
import { augmentAppWithServiceWorker } from '../angular-cli-files/utilities/service-worker';
4245
import {
4346
statsErrorsToString,
4447
statsToString,
4548
statsWarningsToString,
4649
} from '../angular-cli-files/utilities/stats';
4750
import { ExecutionTransformer } from '../transforms';
48-
import { deleteOutputDir } from '../utils';
51+
import { deleteOutputDir, isEs5SupportNeeded } from '../utils';
4952
import { generateBrowserWebpackConfigFromContext } from '../utils/webpack-browser-config';
5053
import { Schema as BrowserBuilderSchema } from './schema';
5154

@@ -182,6 +185,19 @@ export function buildWebpackBrowser(
182185
normalize(workspace.getProject(projectName).root),
183186
);
184187

188+
const tsConfigPath = path.resolve(workspace.root, options.tsConfig);
189+
const tsConfig = readTsconfig(tsConfigPath);
190+
191+
if (isEs5SupportNeeded(projectRoot) &&
192+
tsConfig.options.target !== ts.ScriptTarget.ES5 &&
193+
tsConfig.options.target !== ts.ScriptTarget.ES2015) {
194+
context.logger.warn(tags.stripIndent`
195+
WARNING: Using differential loading with targets ES5 and ES2016 or higher may
196+
cause problems. Browsers with support for ES2015 will load the ES2016+ scripts
197+
referenced with script[type="module"] but they may not support ES2016+ syntax.
198+
`);
199+
}
200+
185201
return from(configs).pipe(
186202
// the concurrency parameter (3rd parameter of mergeScan) is deliberately
187203
// set to 1 to make sure the build steps are executed in sequence.

0 commit comments

Comments
 (0)