-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathutils.ts
More file actions
91 lines (78 loc) · 2.84 KB
/
utils.ts
File metadata and controls
91 lines (78 loc) · 2.84 KB
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
85
86
87
88
89
90
91
/**
* @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
*/
// tslint:disable
// TODO: cleanup this file, it's copied as is from Angular CLI.
import * as path from 'path';
import { basename, normalize } from '@angular-devkit/core';
import { ExtraEntryPoint, ExtraEntryPointObject } from '../../../browser/schema';
import { SourceMapDevToolPlugin } from 'webpack';
export const ngAppResolve = (resolvePath: string): string => {
return path.resolve(process.cwd(), resolvePath);
};
export interface HashFormat {
chunk: string;
extract: string;
file: string;
script: string;
}
export function getOutputHashFormat(option: string, length = 20): HashFormat {
/* tslint:disable:max-line-length */
const hashFormats: { [option: string]: HashFormat } = {
none: { chunk: '', extract: '', file: '' , script: '' },
media: { chunk: '', extract: '', file: `.[hash:${length}]`, script: '' },
bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: '' , script: `.[hash:${length}]` },
all: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]`, script: `.[hash:${length}]` },
};
/* tslint:enable:max-line-length */
return hashFormats[option] || hashFormats['none'];
}
export type NormalizedEntryPoint = ExtraEntryPointObject & { bundleName: string };
export function normalizeExtraEntryPoints(
extraEntryPoints: ExtraEntryPoint[],
defaultBundleName: string
): NormalizedEntryPoint[] {
return extraEntryPoints.map(entry => {
let normalizedEntry;
if (typeof entry === 'string') {
normalizedEntry = { input: entry, lazy: false, bundleName: defaultBundleName };
} else {
let bundleName;
if (entry.bundleName) {
bundleName = entry.bundleName;
} else if (entry.lazy) {
// Lazy entry points use the file name as bundle name.
bundleName = basename(
normalize(entry.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')),
);
} else {
bundleName = defaultBundleName;
}
normalizedEntry = {...entry, bundleName};
}
return normalizedEntry;
})
}
export function getSourceMapDevTool(
scriptsSourceMap: boolean,
stylesSourceMap: boolean,
hiddenSourceMap = false,
inlineSourceMap = false,
): SourceMapDevToolPlugin {
const include = [];
if (scriptsSourceMap) {
include.push(/js$/);
}
if (stylesSourceMap) {
include.push(/css$/);
}
return new SourceMapDevToolPlugin({
filename: inlineSourceMap ? undefined : '[file].map',
include,
append: hiddenSourceMap ? false : undefined,
});
}