UNPKG

3.17 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.maxWorkers = exports.profilingEnabled = exports.cachingBasePath = exports.cachingDisabled = exports.allowMinify = exports.shouldBeautify = exports.allowMangle = void 0;
11const path = require("path");
12function isDisabled(variable) {
13 return variable === '0' || variable.toLowerCase() === 'false';
14}
15function isEnabled(variable) {
16 return variable === '1' || variable.toLowerCase() === 'true';
17}
18function isPresent(variable) {
19 return typeof variable === 'string' && variable !== '';
20}
21// Optimization and mangling
22const debugOptimizeVariable = process.env['NG_BUILD_DEBUG_OPTIMIZE'];
23const debugOptimize = (() => {
24 if (!isPresent(debugOptimizeVariable) || isDisabled(debugOptimizeVariable)) {
25 return {
26 mangle: true,
27 minify: true,
28 beautify: false,
29 };
30 }
31 const debugValue = {
32 mangle: false,
33 minify: false,
34 beautify: true,
35 };
36 if (isEnabled(debugOptimizeVariable)) {
37 return debugValue;
38 }
39 for (const part of debugOptimizeVariable.split(',')) {
40 switch (part.trim().toLowerCase()) {
41 case 'mangle':
42 debugValue.mangle = true;
43 break;
44 case 'minify':
45 debugValue.minify = true;
46 break;
47 case 'beautify':
48 debugValue.beautify = true;
49 break;
50 }
51 }
52 return debugValue;
53})();
54const mangleVariable = process.env['NG_BUILD_MANGLE'];
55exports.allowMangle = isPresent(mangleVariable)
56 ? !isDisabled(mangleVariable)
57 : debugOptimize.mangle;
58exports.shouldBeautify = debugOptimize.beautify;
59exports.allowMinify = debugOptimize.minify;
60// Build cache
61const cacheVariable = process.env['NG_BUILD_CACHE'];
62exports.cachingDisabled = isPresent(cacheVariable) && isDisabled(cacheVariable);
63exports.cachingBasePath = (() => {
64 if (exports.cachingDisabled || !isPresent(cacheVariable) || isEnabled(cacheVariable)) {
65 return null;
66 }
67 if (!path.isAbsolute(cacheVariable)) {
68 throw new Error('NG_BUILD_CACHE path value must be absolute.');
69 }
70 return cacheVariable;
71})();
72// Build profiling
73const profilingVariable = process.env['NG_BUILD_PROFILING'];
74exports.profilingEnabled = isPresent(profilingVariable) && isEnabled(profilingVariable);
75/**
76 * Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
77 * This cause `Error: Call retries were exceeded` errors when trying to use them.
78 *
79 * @see https://github.com/nodejs/node/issues/28762
80 * @see https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
81 * @see https://ithub.com/angular/angular-cli/issues/16860#issuecomment-588828079
82 *
83 */
84const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];
85exports.maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4;