8
8
9
9
import { BuilderContext } from '@angular-devkit/architect' ;
10
10
import { 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' ;
17
11
import { generateBudgetStats } from '../../tools/esbuild/budget-stats' ;
18
12
import { BuildOutputFileType , BundlerContext } from '../../tools/esbuild/bundler-context' ;
19
13
import { ExecutionResult , RebuildState } from '../../tools/esbuild/bundler-execution-result' ;
20
14
import { checkCommonJSModules } from '../../tools/esbuild/commonjs-checker' ;
21
- import { createGlobalScriptsBundleOptions } from '../../tools/esbuild/global-scripts' ;
22
- import { createGlobalStylesBundleOptions } from '../../tools/esbuild/global-styles' ;
23
15
import { extractLicenses } from '../../tools/esbuild/license-extractor' ;
24
16
import {
25
17
calculateEstimatedTransferSizes ,
26
- getSupportedNodeTargets ,
27
18
logBuildStats ,
28
19
logMessages ,
29
- transformSupportedBrowsersToTargets ,
30
20
} from '../../tools/esbuild/utils' ;
31
21
import { BudgetCalculatorResult , checkBudgets } from '../../utils/bundle-calculator' ;
32
22
import { colors } from '../../utils/color' ;
@@ -35,8 +25,8 @@ import { getSupportedBrowsers } from '../../utils/supported-browsers';
35
25
import { executePostBundleSteps } from './execute-post-bundle' ;
36
26
import { inlineI18n , loadActiveTranslations } from './i18n' ;
37
27
import { NormalizedApplicationBuildOptions } from './options' ;
28
+ import { setupBundlerContexts } from './setup-bundling' ;
38
29
39
- // eslint-disable-next-line max-lines-per-function
40
30
export async function executeBuild (
41
31
options : NormalizedApplicationBuildOptions ,
42
32
context : BuilderContext ,
@@ -47,16 +37,13 @@ export async function executeBuild(
47
37
workspaceRoot,
48
38
i18nOptions,
49
39
optimizationOptions,
50
- serverEntryPoint,
51
40
assets,
52
41
cacheOptions,
53
42
prerenderOptions,
54
- appShellOptions,
55
- ssrOptions,
56
43
} = options ;
57
44
45
+ // TODO: Consider integrating into watch mode. Would require full rebuild on target changes.
58
46
const browsers = getSupportedBrowsers ( projectRoot , context . logger ) ;
59
- const target = transformSupportedBrowsersToTargets ( browsers ) ;
60
47
61
48
// Load active translations if inlining
62
49
// TODO: Integrate into watch mode and only load changed translations
@@ -70,93 +57,7 @@ export async function executeBuild(
70
57
rebuildState ?. codeBundleCache ??
71
58
new SourceFileCache ( cacheOptions . enabled ? cacheOptions . path : undefined ) ;
72
59
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 ) ;
160
61
}
161
62
162
63
const bundlingResult = await BundlerContext . bundleAll (
0 commit comments