-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathindex.ts
82 lines (73 loc) · 2.6 KB
/
index.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
/**
* @license
* Copyright Google LLC 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.dev/license
*/
import { type ApplicationBuilderOptions, buildApplication } from '@angular/build';
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import type { Plugin } from 'esbuild';
import type { Schema as BrowserBuilderOptions } from './schema';
export type { BrowserBuilderOptions };
type OutputPathClass = Exclude<ApplicationBuilderOptions['outputPath'], string | undefined>;
/**
* Main execution function for the esbuild-based application builder.
* The options are compatible with the Webpack-based builder.
* @param userOptions The browser builder options to use when setting up the application build
* @param context The Architect builder context object
* @returns An async iterable with the builder result output
*/
export async function* buildEsbuildBrowser(
userOptions: BrowserBuilderOptions,
context: BuilderContext,
infrastructureSettings?: {
write?: boolean;
},
plugins?: Plugin[],
): AsyncIterable<BuilderOutput> {
// Warn about any unsupported options
if (userOptions['vendorChunk']) {
context.logger.warn(
`The 'vendorChunk' option is not used by this builder and will be ignored.`,
);
}
if (userOptions['commonChunk'] === false) {
context.logger.warn(
`The 'commonChunk' option is always enabled by this builder and will be ignored.`,
);
}
if (userOptions['webWorkerTsConfig']) {
context.logger.warn(`The 'webWorkerTsConfig' option is not yet supported by this builder.`);
}
// Convert browser builder options to application builder options
const normalizedOptions = convertBrowserOptions(userOptions);
// Execute the application builder
yield* buildApplication(normalizedOptions, context, { codePlugins: plugins });
}
export function convertBrowserOptions(
options: BrowserBuilderOptions,
): Omit<ApplicationBuilderOptions, 'outputPath'> & { outputPath: OutputPathClass } {
const {
main: browser,
outputPath,
ngswConfigPath,
serviceWorker,
polyfills,
resourcesOutputPath,
...otherOptions
} = options;
return {
browser,
serviceWorker: serviceWorker ? ngswConfigPath : false,
polyfills: typeof polyfills === 'string' ? [polyfills] : polyfills,
outputPath: {
base: outputPath,
browser: '',
server: '',
media: resourcesOutputPath ?? 'media',
},
...otherOptions,
};
}
export default createBuilder<BrowserBuilderOptions>(buildEsbuildBrowser);