Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,43 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
entryPoints['main'] = [path.resolve(root, buildOptions.main)];
}

const es5Polyfills = path.join(__dirname, '..', 'es5-polyfills.js');
const es5JitPolyfills = path.join(__dirname, '..', 'es5-jit-polyfills.js');

if (targetInFileName) {
// For differential loading we don't need to have 2 polyfill bundles
if (buildOptions.scriptTargetOverride === ScriptTarget.ES2015) {
entryPoints['polyfills'] = [path.join(__dirname, '..', 'safari-nomodule.js')];
} else {
entryPoints['polyfills'] = [es5Polyfills];
if (!buildOptions.aot) {
entryPoints['polyfills'].push(es5JitPolyfills);
if (wco.buildOptions.platform !== 'server') {
const es5Polyfills = path.join(__dirname, '..', 'es5-polyfills.js');
const es5JitPolyfills = path.join(__dirname, '..', 'es5-jit-polyfills.js');
if (targetInFileName) {
// For differential loading we don't need to have 2 polyfill bundles
if (buildOptions.scriptTargetOverride === ScriptTarget.ES2015) {
entryPoints['polyfills'] = [path.join(__dirname, '..', 'safari-nomodule.js')];
} else {
entryPoints['polyfills'] = [es5Polyfills];
if (!buildOptions.aot) {
entryPoints['polyfills'].push(es5JitPolyfills);
}
}
}
} else {
// For NON differential loading we want to have 2 polyfill bundles
if (buildOptions.es5BrowserSupport
|| (buildOptions.es5BrowserSupport === undefined && isEs5SupportNeeded(projectRoot))) {
entryPoints['polyfills-es5'] = [es5Polyfills];
if (!buildOptions.aot) {
entryPoints['polyfills-es5'].push(es5JitPolyfills);
} else {
// For NON differential loading we want to have 2 polyfill bundles
if (buildOptions.es5BrowserSupport
|| (buildOptions.es5BrowserSupport === undefined && isEs5SupportNeeded(projectRoot))) {
entryPoints['polyfills-es5'] = [es5Polyfills];
if (!buildOptions.aot) {
entryPoints['polyfills-es5'].push(es5JitPolyfills);
}
}
}
}

if (buildOptions.polyfills) {
entryPoints['polyfills'] = [
...(entryPoints['polyfills'] || []),
path.resolve(root, buildOptions.polyfills),
];
}
if (buildOptions.polyfills) {
entryPoints['polyfills'] = [
...(entryPoints['polyfills'] || []),
path.resolve(root, buildOptions.polyfills),
];
}

if (!buildOptions.aot) {
entryPoints['polyfills'] = [
...(entryPoints['polyfills'] || []),
path.join(__dirname, '..', 'jit-polyfills.js'),
];
if (!buildOptions.aot) {
entryPoints['polyfills'] = [
...(entryPoints['polyfills'] || []),
path.join(__dirname, '..', 'jit-polyfills.js'),
];
}
}

if (buildOptions.profile || process.env['NG_BUILD_PROFILING']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { join, normalize, virtualFs } from '@angular-devkit/core';
import { getSystemPath, join, normalize, virtualFs } from '@angular-devkit/core';
import { take, tap } from 'rxjs/operators';
import { BrowserBuilderOutput } from '../../src/browser';
import { createArchitect, host } from '../utils';
Expand Down Expand Up @@ -37,6 +37,34 @@ describe('Server Builder', () => {
await run.stop();
});

it('should not emit polyfills', async () => {
const run = await architect.scheduleTarget(target);
const output = await run.result as BrowserBuilderOutput;
expect(output.success).toBe(true);

expect(host.fileMatchExists(getSystemPath(outputPath), /polyfills/)).not.toBeDefined();
expect(host.fileMatchExists(getSystemPath(outputPath), /main/)).toBeDefined();

await run.stop();
});

it('should not emit polyfills when ES5 support is needed', async () => {
// the below is needed because of different code paths
// for polyfills if differential loading is needed
host.writeMultipleFiles({
'browserslist': 'IE 10',
});

const run = await architect.scheduleTarget(target);
const output = await run.result as BrowserBuilderOutput;
expect(output.success).toBe(true);

expect(host.fileMatchExists(getSystemPath(outputPath), /polyfills/)).not.toBeDefined();
expect(host.fileMatchExists(getSystemPath(outputPath), /main/)).toBeDefined();

await run.stop();
});

it('supports sourcemaps', async () => {
const overrides = { sourceMap: true };

Expand Down