@@ -125,8 +125,8 @@ export function createCompilerPlugin(
125
125
new Map < string , string | Uint8Array > ( ) ;
126
126
127
127
// The stylesheet resources from component stylesheets that will be added to the build results output files
128
- let stylesheetResourceFiles : OutputFile [ ] = [ ] ;
129
- let stylesheetMetafiles : Metafile [ ] ;
128
+ let additionalOutputFiles : OutputFile [ ] = [ ] ;
129
+ let additionalMetafiles : Metafile [ ] ;
130
130
131
131
// Create new reusable compilation for the appropriate mode based on the `jit` plugin option
132
132
const compilation : AngularCompilation = pluginOptions . noopTypeScriptCompilation
@@ -146,9 +146,9 @@ export function createCompilerPlugin(
146
146
// Reset debug performance tracking
147
147
resetCumulativeDurations ( ) ;
148
148
149
- // Reset stylesheet resource output files
150
- stylesheetResourceFiles = [ ] ;
151
- stylesheetMetafiles = [ ] ;
149
+ // Reset additional output files
150
+ additionalOutputFiles = [ ] ;
151
+ additionalMetafiles = [ ] ;
152
152
153
153
// Create Angular compiler host options
154
154
const hostOptions : AngularHostOptions = {
@@ -173,31 +173,50 @@ export function createCompilerPlugin(
173
173
( result . errors ??= [ ] ) . push ( ...errors ) ;
174
174
}
175
175
( result . warnings ??= [ ] ) . push ( ...warnings ) ;
176
- stylesheetResourceFiles . push ( ...resourceFiles ) ;
176
+ additionalOutputFiles . push ( ...resourceFiles ) ;
177
177
if ( stylesheetResult . metafile ) {
178
- stylesheetMetafiles . push ( stylesheetResult . metafile ) ;
178
+ additionalMetafiles . push ( stylesheetResult . metafile ) ;
179
179
}
180
180
181
181
return contents ;
182
182
} ,
183
183
processWebWorker ( workerFile , containingFile ) {
184
- // TODO: Implement bundling of the worker
185
- // This temporarily issues a warning that workers are not yet processed.
186
- ( result . warnings ??= [ ] ) . push ( {
187
- text : 'Processing of Web Worker files is not yet implemented.' ,
188
- location : null ,
189
- notes : [
190
- {
191
- text : `The worker entry point file '${ workerFile } ' found in '${ path . relative (
192
- styleOptions . workspaceRoot ,
193
- containingFile ,
194
- ) } ' will not be present in the output.`,
195
- } ,
196
- ] ,
184
+ const fullWorkerPath = path . join ( path . dirname ( containingFile ) , workerFile ) ;
185
+ // The synchronous API must be used due to the TypeScript compilation currently being
186
+ // fully synchronous and this process callback being called from within a TypeScript
187
+ // transformer.
188
+ const workerResult = build . esbuild . buildSync ( {
189
+ platform : 'browser' ,
190
+ write : false ,
191
+ bundle : true ,
192
+ metafile : true ,
193
+ format : 'esm' ,
194
+ mainFields : [ 'es2020' , 'es2015' , 'browser' , 'module' , 'main' ] ,
195
+ sourcemap : pluginOptions . sourcemap ,
196
+ entryNames : 'worker-[hash]' ,
197
+ entryPoints : [ fullWorkerPath ] ,
198
+ absWorkingDir : build . initialOptions . absWorkingDir ,
199
+ outdir : build . initialOptions . outdir ,
200
+ minifyIdentifiers : build . initialOptions . minifyIdentifiers ,
201
+ minifySyntax : build . initialOptions . minifySyntax ,
202
+ minifyWhitespace : build . initialOptions . minifyWhitespace ,
203
+ target : build . initialOptions . target ,
197
204
} ) ;
198
205
199
- // Returning the original file prevents modification to the containing file
200
- return workerFile ;
206
+ if ( workerResult . errors ) {
207
+ ( result . errors ??= [ ] ) . push ( ...workerResult . errors ) ;
208
+ }
209
+ ( result . warnings ??= [ ] ) . push ( ...workerResult . warnings ) ;
210
+ additionalOutputFiles . push ( ...workerResult . outputFiles ) ;
211
+ if ( workerResult . metafile ) {
212
+ additionalMetafiles . push ( workerResult . metafile ) ;
213
+ }
214
+
215
+ // Return bundled worker file entry name to be used in the built output
216
+ return path . relative (
217
+ build . initialOptions . outdir ?? '' ,
218
+ workerResult . outputFiles [ 0 ] . path ,
219
+ ) ;
201
220
} ,
202
221
} ;
203
222
@@ -365,20 +384,20 @@ export function createCompilerPlugin(
365
384
setupJitPluginCallbacks (
366
385
build ,
367
386
styleOptions ,
368
- stylesheetResourceFiles ,
387
+ additionalOutputFiles ,
369
388
pluginOptions . loadResultCache ,
370
389
) ;
371
390
}
372
391
373
392
build . onEnd ( ( result ) => {
374
- // Add any component stylesheet resource files to the output files
375
- if ( stylesheetResourceFiles . length ) {
376
- result . outputFiles ?. push ( ...stylesheetResourceFiles ) ;
393
+ // Add any additional output files to the main output files
394
+ if ( additionalOutputFiles . length ) {
395
+ result . outputFiles ?. push ( ...additionalOutputFiles ) ;
377
396
}
378
397
379
- // Combine component stylesheet metafiles with main metafile
380
- if ( result . metafile && stylesheetMetafiles . length ) {
381
- for ( const metafile of stylesheetMetafiles ) {
398
+ // Combine additional metafiles with main metafile
399
+ if ( result . metafile && additionalMetafiles . length ) {
400
+ for ( const metafile of additionalMetafiles ) {
382
401
result . metafile . inputs = { ...result . metafile . inputs , ...metafile . inputs } ;
383
402
result . metafile . outputs = { ...result . metafile . outputs , ...metafile . outputs } ;
384
403
}
0 commit comments