Skip to content

fix(@angular-devkit/build-angular): mangle scripts when differential loading is enabled #15507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 17 additions & 14 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,15 @@ export function buildWebpackBrowser(

const actions: ProcessBundleOptions[] = [];
const seen = new Set<string>();
files = [];
for (const file of emittedFiles) {
// Assets are not processed nor injected into the index
if (file.asset) {
continue;
}

// Scripts and non-javascript files are not processed
if (
file.extension !== '.js' ||
(file.name && scriptsEntryPointName.includes(file.name))
) {
if (files === undefined) {
files = [];
}
// Non-javascript files are not processed
if (file.extension !== '.js') {
files.push(file);
continue;
}
Expand All @@ -312,14 +307,21 @@ export function buildWebpackBrowser(
}
seen.add(file.file);

const isScriptFile = file.name && scriptsEntryPointName.includes(file.name);
if (isScriptFile) {
files.push(file);
}

// If not optimizing then ES2015 polyfills and Scripts do not need processing
// Unlike other module scripts, they are never downleveled
const isOptimizeOnlyFile = file.file.startsWith('polyfills-es2015') || isScriptFile;

// All files at this point except ES5 polyfills are module scripts
const es5Polyfills = file.file.startsWith('polyfills-es5');
if (!es5Polyfills && !file.file.startsWith('polyfills-nomodule-es5')) {
if (!isScriptFile && !es5Polyfills && !file.file.startsWith('polyfills-nomodule-es5')) {
moduleFiles.push(file);
}
// If not optimizing then ES2015 polyfills do not need processing
// Unlike other module scripts, it is never downleveled
if (!actionOptions.optimize && file.file.startsWith('polyfills-es2015')) {
if (!actionOptions.optimize && isOptimizeOnlyFile) {
continue;
}

Expand All @@ -342,14 +344,15 @@ export function buildWebpackBrowser(
filename = filename.replace('-es2015', '');
}

// ES2015 polyfills are only optimized; optimization check was performed above
if (file.file.startsWith('polyfills-es2015')) {
// ES2015 polyfills and scripts only needs to be optimized
if (isOptimizeOnlyFile) {
actions.push({
...actionOptions,
filename,
code,
map,
optimizeOnly: true,
ecma: isScriptFile ? 5 : 6,
});

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { SourceMapConsumer, SourceMapGenerator } from 'source-map';
import { minify } from 'terser';
import { ECMA, minify } from 'terser';
import { manglingDisabled } from './mangle-options';

const { transformAsync } = require('@babel/core');
Expand All @@ -27,6 +27,7 @@ export interface ProcessBundleOptions {
ignoreOriginal?: boolean;
cacheKeys?: (string | null)[];
cachePath?: string;
ecma?: ECMA;
}

export const enum CacheKey {
Expand Down Expand Up @@ -183,7 +184,7 @@ async function processWorker(options: ProcessBundleOptions): Promise<void> {
async function mangleOriginal(options: ProcessBundleOptions): Promise<void> {
const resultOriginal = minify(options.code, {
compress: false,
ecma: 6,
ecma: options.ecma || 6,
mangle: !manglingDisabled,
safari10: true,
output: {
Expand Down