88
99import { BuilderContext } from '@angular-devkit/architect' ;
1010import { SourceFileCache } from '../../tools/esbuild/angular/source-file-cache' ;
11- import {
12- createBrowserCodeBundleOptions ,
13- createBrowserPolyfillBundleOptions ,
14- createServerCodeBundleOptions ,
15- createServerPolyfillBundleOptions ,
16- } from '../../tools/esbuild/application-code-bundle' ;
1711import { generateBudgetStats } from '../../tools/esbuild/budget-stats' ;
1812import { BuildOutputFileType , BundlerContext } from '../../tools/esbuild/bundler-context' ;
1913import { ExecutionResult , RebuildState } from '../../tools/esbuild/bundler-execution-result' ;
2014import { checkCommonJSModules } from '../../tools/esbuild/commonjs-checker' ;
21- import { createGlobalScriptsBundleOptions } from '../../tools/esbuild/global-scripts' ;
22- import { createGlobalStylesBundleOptions } from '../../tools/esbuild/global-styles' ;
2315import { extractLicenses } from '../../tools/esbuild/license-extractor' ;
2416import {
2517 calculateEstimatedTransferSizes ,
26- getSupportedNodeTargets ,
2718 logBuildStats ,
2819 logMessages ,
29- transformSupportedBrowsersToTargets ,
3020} from '../../tools/esbuild/utils' ;
3121import { BudgetCalculatorResult , checkBudgets } from '../../utils/bundle-calculator' ;
3222import { colors } from '../../utils/color' ;
@@ -35,8 +25,8 @@ import { getSupportedBrowsers } from '../../utils/supported-browsers';
3525import { executePostBundleSteps } from './execute-post-bundle' ;
3626import { inlineI18n , loadActiveTranslations } from './i18n' ;
3727import { NormalizedApplicationBuildOptions } from './options' ;
28+ import { setupBundlerContexts } from './setup-bundling' ;
3829
39- // eslint-disable-next-line max-lines-per-function
4030export async function executeBuild (
4131 options : NormalizedApplicationBuildOptions ,
4232 context : BuilderContext ,
@@ -47,16 +37,13 @@ export async function executeBuild(
4737 workspaceRoot,
4838 i18nOptions,
4939 optimizationOptions,
50- serverEntryPoint,
5140 assets,
5241 cacheOptions,
5342 prerenderOptions,
54- appShellOptions,
55- ssrOptions,
5643 } = options ;
5744
45+ // TODO: Consider integrating into watch mode. Would require full rebuild on target changes.
5846 const browsers = getSupportedBrowsers ( projectRoot , context . logger ) ;
59- const target = transformSupportedBrowsersToTargets ( browsers ) ;
6047
6148 // Load active translations if inlining
6249 // TODO: Integrate into watch mode and only load changed translations
@@ -70,93 +57,7 @@ export async function executeBuild(
7057 rebuildState ?. codeBundleCache ??
7158 new SourceFileCache ( cacheOptions . enabled ? cacheOptions . path : undefined ) ;
7259 if ( bundlerContexts === undefined ) {
73- bundlerContexts = [ ] ;
74-
75- // Browser application code
76- bundlerContexts . push (
77- new BundlerContext (
78- workspaceRoot ,
79- ! ! options . watch ,
80- createBrowserCodeBundleOptions ( options , target , codeBundleCache ) ,
81- ) ,
82- ) ;
83-
84- // Browser polyfills code
85- const browserPolyfillBundleOptions = createBrowserPolyfillBundleOptions (
86- options ,
87- target ,
88- codeBundleCache ,
89- ) ;
90- if ( browserPolyfillBundleOptions ) {
91- bundlerContexts . push (
92- new BundlerContext ( workspaceRoot , ! ! options . watch , browserPolyfillBundleOptions ) ,
93- ) ;
94- }
95-
96- // Global Stylesheets
97- if ( options . globalStyles . length > 0 ) {
98- for ( const initial of [ true , false ] ) {
99- const bundleOptions = createGlobalStylesBundleOptions ( options , target , initial ) ;
100- if ( bundleOptions ) {
101- bundlerContexts . push (
102- new BundlerContext ( workspaceRoot , ! ! options . watch , bundleOptions , ( ) => initial ) ,
103- ) ;
104- }
105- }
106- }
107-
108- // Global Scripts
109- if ( options . globalScripts . length > 0 ) {
110- for ( const initial of [ true , false ] ) {
111- const bundleOptions = createGlobalScriptsBundleOptions ( options , target , initial ) ;
112- if ( bundleOptions ) {
113- bundlerContexts . push (
114- new BundlerContext ( workspaceRoot , ! ! options . watch , bundleOptions , ( ) => initial ) ,
115- ) ;
116- }
117- }
118- }
119-
120- // Skip server build when none of the features are enabled.
121- if ( serverEntryPoint && ( prerenderOptions || appShellOptions || ssrOptions ) ) {
122- const nodeTargets = [ ...target , ...getSupportedNodeTargets ( ) ] ;
123- // Server application code
124- bundlerContexts . push (
125- new BundlerContext (
126- workspaceRoot ,
127- ! ! options . watch ,
128- createServerCodeBundleOptions (
129- {
130- ...options ,
131- // Disable external deps for server bundles.
132- // This is because it breaks Vite 'optimizeDeps' for SSR.
133- externalPackages : false ,
134- } ,
135- nodeTargets ,
136- codeBundleCache ,
137- ) ,
138- ( ) => false ,
139- ) ,
140- ) ;
141-
142- // Server polyfills code
143- const serverPolyfillBundleOptions = createServerPolyfillBundleOptions (
144- options ,
145- nodeTargets ,
146- codeBundleCache ,
147- ) ;
148-
149- if ( serverPolyfillBundleOptions ) {
150- bundlerContexts . push (
151- new BundlerContext (
152- workspaceRoot ,
153- ! ! options . watch ,
154- serverPolyfillBundleOptions ,
155- ( ) => false ,
156- ) ,
157- ) ;
158- }
159- }
60+ bundlerContexts = setupBundlerContexts ( options , browsers , codeBundleCache ) ;
16061 }
16162
16263 const bundlingResult = await BundlerContext . bundleAll (
0 commit comments