@@ -11,7 +11,7 @@ import * as assert from 'assert';
11
11
import type { Message , OutputFile } from 'esbuild' ;
12
12
import * as fs from 'fs/promises' ;
13
13
import * as path from 'path' ;
14
- import { NormalizedOptimizationOptions , deleteOutputDir } from '../../utils' ;
14
+ import { deleteOutputDir } from '../../utils' ;
15
15
import { copyAssets } from '../../utils/copy-assets' ;
16
16
import { assertIsError } from '../../utils/error' ;
17
17
import { transformSupportedBrowsersToTargets } from '../../utils/esbuild-targets' ;
@@ -22,61 +22,36 @@ import { getSupportedBrowsers } from '../../utils/supported-browsers';
22
22
import { createCompilerPlugin } from './compiler-plugin' ;
23
23
import { bundle , logMessages } from './esbuild' ;
24
24
import { logExperimentalWarnings } from './experimental-warnings' ;
25
- import { normalizeOptions } from './options' ;
26
- import { Schema as BrowserBuilderOptions , SourceMapClass } from './schema' ;
25
+ import { NormalizedBrowserOptions , normalizeOptions } from './options' ;
26
+ import { Schema as BrowserBuilderOptions } from './schema' ;
27
27
import { bundleStylesheetText } from './stylesheets' ;
28
28
import { createWatcher } from './watcher' ;
29
29
30
30
async function execute (
31
- options : BrowserBuilderOptions ,
32
- normalizedOptions : Awaited < ReturnType < typeof normalizeOptions > > ,
31
+ options : NormalizedBrowserOptions ,
33
32
context : BuilderContext ,
34
33
) : Promise < BuilderOutput > {
35
34
const startTime = Date . now ( ) ;
36
35
37
36
const {
38
37
projectRoot,
39
38
workspaceRoot,
40
- entryPoints,
41
39
optimizationOptions,
42
40
outputPath,
43
- sourcemapOptions,
44
- tsconfig,
45
41
assets,
46
- outputNames,
47
- fileReplacements,
48
- globalStyles,
49
42
serviceWorkerOptions,
50
43
indexHtmlOptions,
51
- } = normalizedOptions ;
44
+ } = options ;
52
45
53
46
const target = transformSupportedBrowsersToTargets (
54
47
getSupportedBrowsers ( projectRoot , context . logger ) ,
55
48
) ;
56
49
57
50
const [ codeResults , styleResults ] = await Promise . all ( [
58
51
// Execute esbuild to bundle the application code
59
- bundleCode (
60
- workspaceRoot ,
61
- entryPoints ,
62
- outputNames ,
63
- options ,
64
- optimizationOptions ,
65
- sourcemapOptions ,
66
- tsconfig ,
67
- fileReplacements ,
68
- target ,
69
- ) ,
52
+ bundleCode ( options , target ) ,
70
53
// Execute esbuild to bundle the global stylesheets
71
- bundleGlobalStylesheets (
72
- workspaceRoot ,
73
- outputNames ,
74
- globalStyles ,
75
- options ,
76
- optimizationOptions ,
77
- sourcemapOptions ,
78
- target ,
79
- ) ,
54
+ bundleGlobalStylesheets ( options , target ) ,
80
55
] ) ;
81
56
82
57
// Log all warnings and errors generated during bundling
@@ -204,17 +179,21 @@ function createOutputFileFromText(path: string, text: string): OutputFile {
204
179
} ;
205
180
}
206
181
207
- async function bundleCode (
208
- workspaceRoot : string ,
209
- entryPoints : Record < string , string > ,
210
- outputNames : { bundles : string ; media : string } ,
211
- options : BrowserBuilderOptions ,
212
- optimizationOptions : NormalizedOptimizationOptions ,
213
- sourcemapOptions : SourceMapClass ,
214
- tsconfig : string ,
215
- fileReplacements : Record < string , string > | undefined ,
216
- target : string [ ] ,
217
- ) {
182
+ async function bundleCode ( options : NormalizedBrowserOptions , target : string [ ] ) {
183
+ const {
184
+ workspaceRoot,
185
+ entryPoints,
186
+ optimizationOptions,
187
+ sourcemapOptions,
188
+ tsconfig,
189
+ outputNames,
190
+ fileReplacements,
191
+ externalDependencies,
192
+ preserveSymlinks,
193
+ stylePreprocessorOptions,
194
+ advancedOptimizations,
195
+ } = options ;
196
+
218
197
return bundle ( {
219
198
absWorkingDir : workspaceRoot ,
220
199
bundle : true ,
@@ -242,18 +221,18 @@ async function bundleCode(
242
221
sourcemap : sourcemapOptions . scripts && ( sourcemapOptions . hidden ? 'external' : true ) ,
243
222
splitting : true ,
244
223
tsconfig,
245
- external : options . externalDependencies ,
224
+ external : externalDependencies ,
246
225
write : false ,
247
226
platform : 'browser' ,
248
- preserveSymlinks : options . preserveSymlinks ,
227
+ preserveSymlinks,
249
228
plugins : [
250
229
createCompilerPlugin (
251
230
// JS/TS options
252
231
{
253
232
sourcemap : ! ! sourcemapOptions . scripts ,
254
233
thirdPartySourcemaps : sourcemapOptions . vendor ,
255
234
tsconfig,
256
- advancedOptimizations : options . buildOptimizer ,
235
+ advancedOptimizations,
257
236
fileReplacements,
258
237
} ,
259
238
// Component stylesheet options
@@ -266,8 +245,8 @@ async function bundleCode(
266
245
// of sourcemap processing.
267
246
! ! sourcemapOptions . styles && ( sourcemapOptions . hidden ? false : 'inline' ) ,
268
247
outputNames,
269
- includePaths : options . stylePreprocessorOptions ?. includePaths ,
270
- externalDependencies : options . externalDependencies ,
248
+ includePaths : stylePreprocessorOptions ?. includePaths ,
249
+ externalDependencies,
271
250
target,
272
251
} ,
273
252
) ,
@@ -279,15 +258,18 @@ async function bundleCode(
279
258
} ) ;
280
259
}
281
260
282
- async function bundleGlobalStylesheets (
283
- workspaceRoot : string ,
284
- outputNames : { bundles : string ; media : string } ,
285
- globalStyles : { name : string ; files : string [ ] ; initial : boolean } [ ] ,
286
- options : BrowserBuilderOptions ,
287
- optimizationOptions : NormalizedOptimizationOptions ,
288
- sourcemapOptions : SourceMapClass ,
289
- target : string [ ] ,
290
- ) {
261
+ async function bundleGlobalStylesheets ( options : NormalizedBrowserOptions , target : string [ ] ) {
262
+ const {
263
+ workspaceRoot,
264
+ optimizationOptions,
265
+ sourcemapOptions,
266
+ outputNames,
267
+ globalStyles,
268
+ preserveSymlinks,
269
+ externalDependencies,
270
+ stylePreprocessorOptions,
271
+ } = options ;
272
+
291
273
const outputFiles : OutputFile [ ] = [ ] ;
292
274
const initialFiles : FileInfo [ ] = [ ] ;
293
275
const errors : Message [ ] = [ ] ;
@@ -305,9 +287,9 @@ async function bundleGlobalStylesheets(
305
287
optimization : ! ! optimizationOptions . styles . minify ,
306
288
sourcemap : ! ! sourcemapOptions . styles && ( sourcemapOptions . hidden ? 'external' : true ) ,
307
289
outputNames : initial ? outputNames : { media : outputNames . media } ,
308
- includePaths : options . stylePreprocessorOptions ?. includePaths ,
309
- preserveSymlinks : options . preserveSymlinks ,
310
- externalDependencies : options . externalDependencies ,
290
+ includePaths : stylePreprocessorOptions ?. includePaths ,
291
+ preserveSymlinks,
292
+ externalDependencies,
311
293
target,
312
294
} ,
313
295
) ;
@@ -401,7 +383,7 @@ export async function* buildEsbuildBrowser(
401
383
}
402
384
403
385
// Initial build
404
- yield await execute ( initialOptions , normalizedOptions , context ) ;
386
+ yield await execute ( normalizedOptions , context ) ;
405
387
406
388
// Finish if watch mode is not enabled
407
389
if ( ! initialOptions . watch ) {
@@ -434,7 +416,7 @@ export async function* buildEsbuildBrowser(
434
416
context . logger . info ( changes . toDebugString ( ) ) ;
435
417
}
436
418
437
- yield await execute ( initialOptions , normalizedOptions , context ) ;
419
+ yield await execute ( normalizedOptions , context ) ;
438
420
}
439
421
} finally {
440
422
await watcher . close ( ) ;
0 commit comments