Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): remove differential loading support
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Differential loading support has been removed. With Angular no longer supporting IE11, there are now no browsers officially supported by Angular that require ES5 code. As a result, differential loading's functionality for creating and conditionally loading ES5 and ES2015+ variants of an application is no longer required.
  • Loading branch information
clydin authored and filipesilva committed Aug 2, 2021
1 parent a15875a commit 701214d
Show file tree
Hide file tree
Showing 34 changed files with 135 additions and 2,357 deletions.
407 changes: 28 additions & 379 deletions packages/angular_devkit/build_angular/src/browser/index.ts

Large diffs are not rendered by default.

Expand Up @@ -17,9 +17,6 @@ describe('Browser Builder browser support', () => {
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;

// target ES5 to disable differential loading which is not needed for the tests
host.replaceInFile('tsconfig.json', '"target": "es2017"', '"target": "es5"');
});
afterEach(async () => host.restore().toPromise());

Expand Down

This file was deleted.

Expand Up @@ -75,40 +75,6 @@ describe('Browser Builder scripts array', () => {
}
});

it('works in watch mode with differential loading', async () => {
const matches: Record<string, string> = {
'scripts.js': 'input-script',
'lazy-script.js': 'lazy-script',
'renamed-script.js': 'pre-rename-script',
'renamed-lazy-script.js': 'pre-rename-lazy-script',
'main-es2017.js': 'input-script',
'index.html':
'<script src="runtime-es2017.js" type="module"></script>' +
'<script src="polyfills-es2017.js" type="module"></script>' +
'<script src="scripts.js" defer></script>' +
'<script src="renamed-script.js" defer></script>' +
'<script src="vendor-es2017.js" type="module"></script>' +
'<script src="main-es2017.js" type="module"></script>',
};

host.writeMultipleFiles(scripts);
host.appendToFile('src/main.ts', "\nimport './input-script.js';");

// Enable differential loading
host.appendToFile('.browserslistrc', '\nIE 11');

// Remove styles so we don't have to account for them in the index.html order check.
const { files } = await browserBuild(architect, host, target, {
styles: [],
scripts: getScriptsOption(),
watch: true,
} as {});

for (const [fileName, content] of Object.entries(matches)) {
expect(await files[fileName]).toMatch(content);
}
});

it('uglifies, uses sourcemaps, and adds hashes', async () => {
host.writeMultipleFiles(scripts);

Expand Down
Expand Up @@ -140,9 +140,6 @@ describe('Browser Builder styles', () => {
'.browserslistrc': 'IE 10',
});

// Set target to ES5 to avoid differential loading and unnecessary testing time
host.replaceInFile('tsconfig.json', '"target": "es2017"', '"target": "es5"');

const { files } = await browserBuild(architect, host, target, { aot: false });

expect(await files['main.js']).toContain('-ms-flex: 1;');
Expand All @@ -165,9 +162,6 @@ describe('Browser Builder styles', () => {
'.browserslistrc': 'IE 10',
});

// Set target to ES5 to avoid differential loading and unnecessary testing time
host.replaceInFile('tsconfig.json', '"target": "es2017"', '"target": "es5"');

const { files } = await browserBuild(architect, host, target, { aot: true });

expect(await files['main.js']).toContain('-ms-flex: 1;');
Expand Down Expand Up @@ -354,9 +348,6 @@ describe('Browser Builder styles', () => {
'.browserslistrc': 'IE 10',
});

// Set to target to ES5 to avoid differential loading and unnecessary testing time
host.replaceInFile('tsconfig.json', '"target": "es2017"', '"target": "es5"');

const overrides = { extractCss: true, optimization: false };
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['styles.css']).toContain(tags.stripIndents`
Expand Down Expand Up @@ -394,9 +385,6 @@ describe('Browser Builder styles', () => {
'.browserslistrc': 'IE 10',
});

// Set target to ES5 to avoid differential loading and unnecessary testing time
host.replaceInFile('tsconfig.json', '"target": "es2017"', '"target": "es5"');

const overrides = { extractCss: true, optimization: true, styles: ['src/styles.scss'] };
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['styles.css']).toContain('-ms-grid-columns:100px;');
Expand Down
16 changes: 4 additions & 12 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Expand Up @@ -16,13 +16,12 @@ import { json, tags } from '@angular-devkit/core';
import * as path from 'path';
import { Observable, from } from 'rxjs';
import { concatMap, switchMap } from 'rxjs/operators';
import * as ts from 'typescript';
import * as url from 'url';
import webpack from 'webpack';
import webpackDevServer from 'webpack-dev-server';
import { Schema as BrowserBuilderSchema, OutputHashing } from '../browser/schema';
import { ExecutionTransformer } from '../transforms';
import { BuildBrowserFeatures, normalizeOptimization } from '../utils';
import { normalizeOptimization } from '../utils';
import { findCachePath } from '../utils/cache-path';
import { checkPort } from '../utils/check-port';
import { colors } from '../utils/color';
Expand Down Expand Up @@ -303,17 +302,10 @@ export function serveWebpackBrowser(
}

return from(setup()).pipe(
switchMap(({ browserOptions, webpackConfig, projectRoot, locale }) => {
switchMap(({ browserOptions, webpackConfig, locale }) => {
if (browserOptions.index) {
const { scripts = [], styles = [], baseHref, tsConfig } = browserOptions;
const { options: compilerOptions } = readTsconfig(tsConfig, workspaceRoot);
const target = compilerOptions.target || ts.ScriptTarget.ES5;
const buildBrowserFeatures = new BuildBrowserFeatures(projectRoot);

const { scripts = [], styles = [], baseHref } = browserOptions;
const entrypoints = generateEntryPoints({ scripts, styles });
const moduleEntrypoints = buildBrowserFeatures.isDifferentialLoadingNeeded(target)
? generateEntryPoints({ scripts: [], styles })
: [];

webpackConfig.plugins = [...(webpackConfig.plugins || [])];
webpackConfig.plugins.push(
Expand All @@ -322,7 +314,7 @@ export function serveWebpackBrowser(
outputPath: getIndexOutputFile(browserOptions.index),
baseHref,
entrypoints,
moduleEntrypoints,
moduleEntrypoints: [],
noModuleEntrypoints: ['polyfills-es5'],
deployUrl: browserOptions.deployUrl,
sri: browserOptions.subresourceIntegrity,
Expand Down

0 comments on commit 701214d

Please sign in to comment.