Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): add debug no mangle environm…
Browse files Browse the repository at this point in the history
…ent variable
  • Loading branch information
clydin authored and vikerman committed Aug 29, 2019
1 parent 01a883a commit 96cf51a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { RawSource } from 'webpack-sources';
import { AssetPatternClass, ExtraEntryPoint } from '../../../browser/schema';
import { BuildBrowserFeatures, fullDifferential } from '../../../utils';
import { manglingDisabled } from '../../../utils/mangle-options';
import { BundleBudgetPlugin } from '../../plugins/bundle-budget';
import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin';
import { NamedLazyChunksPlugin } from '../../plugins/named-chunks-plugin';
Expand Down Expand Up @@ -362,6 +363,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
// We also want to avoid mangling on server.
// Name mangling is handled within the browser builder
mangle:
!manglingDisabled &&
buildOptions.platform !== 'server' &&
(!differentialLoadingNeeded || (differentialLoadingNeeded && fullDifferential)),
};
Expand Down
10 changes: 10 additions & 0 deletions packages/angular_devkit/build_angular/src/utils/mangle-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const mangleVariable = process.env['NG_BUILD_MANGLE'];
export const manglingDisabled =
!!mangleVariable && (mangleVariable === '0' || mangleVariable.toLowerCase() === 'false');
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { SourceMapConsumer, SourceMapGenerator } from 'source-map';
import { minify } from 'terser';
import { manglingDisabled } from './mangle-options';

const { transformAsync } = require('@babel/core');
const cacache = require('cacache');
Expand Down Expand Up @@ -134,7 +135,7 @@ async function processWorker(options: ProcessBundleOptions): Promise<void> {
const result = minify(code, {
compress: false,
ecma: 5,
mangle: true,
mangle: !manglingDisabled,
safari10: true,
toplevel: true,
output: {
Expand Down Expand Up @@ -184,7 +185,7 @@ async function mangleOriginal(options: ProcessBundleOptions): Promise<void> {
const resultOriginal = minify(options.code, {
compress: false,
ecma: 6,
mangle: true,
mangle: !manglingDisabled,
safari10: true,
output: {
ascii_only: true,
Expand Down

0 comments on commit 96cf51a

Please sign in to comment.