-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathenvironment-options.ts
84 lines (71 loc) · 2.24 KB
/
environment-options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @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
*/
import * as path from 'path';
function isDisabled(variable: string): boolean {
return variable === '0' || variable.toLowerCase() === 'false';
}
function isEnabled(variable: string): boolean {
return variable === '1' || variable.toLowerCase() === 'true';
}
function isPresent(variable: string | undefined): variable is string {
return typeof variable === 'string' && variable !== '';
}
// Optimization and mangling
const debugOptimizeVariable = process.env['NG_BUILD_DEBUG_OPTIMIZE'];
const debugOptimize = (() => {
if (!isPresent(debugOptimizeVariable) || isDisabled(debugOptimizeVariable)) {
return {
mangle: true,
minify: true,
beautify: false,
};
}
const debugValue = {
mangle: false,
minify: false,
beautify: true,
};
if (isEnabled(debugOptimizeVariable)) {
return debugValue;
}
for (const part of debugOptimizeVariable.split(',')) {
switch (part.trim().toLowerCase()) {
case 'mangle':
debugValue.mangle = true;
break;
case 'minify':
debugValue.minify = true;
break;
case 'beautify':
debugValue.beautify = true;
break;
}
}
return debugValue;
})();
const mangleVariable = process.env['NG_BUILD_MANGLE'];
export const allowMangle = isPresent(mangleVariable)
? !isDisabled(mangleVariable)
: debugOptimize.mangle;
export const shouldBeautify = debugOptimize.beautify;
export const allowMinify = debugOptimize.minify;
// Build cache
const cacheVariable = process.env['NG_BUILD_CACHE'];
export const cachingDisabled = isPresent(cacheVariable) && isDisabled(cacheVariable);
export const cachingBasePath = (() => {
if (cachingDisabled || !isPresent(cacheVariable) || isEnabled(cacheVariable)) {
return null;
}
if (!path.isAbsolute(cacheVariable)) {
throw new Error('NG_BUILD_CACHE path value must be absolute.');
}
return cacheVariable;
})();
// Build profiling
const profilingVariable = process.env['NG_BUILD_PROFILING'];
export const profilingEnabled = isPresent(profilingVariable) && isEnabled(profilingVariable);