@@ -125,8 +125,8 @@ export function createCompilerPlugin(
125125 new Map < string , string | Uint8Array > ( ) ;
126126
127127 // 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 [ ] ;
130130
131131 // Create new reusable compilation for the appropriate mode based on the `jit` plugin option
132132 const compilation : AngularCompilation = pluginOptions . noopTypeScriptCompilation
@@ -146,9 +146,9 @@ export function createCompilerPlugin(
146146 // Reset debug performance tracking
147147 resetCumulativeDurations ( ) ;
148148
149- // Reset stylesheet resource output files
150- stylesheetResourceFiles = [ ] ;
151- stylesheetMetafiles = [ ] ;
149+ // Reset additional output files
150+ additionalOutputFiles = [ ] ;
151+ additionalMetafiles = [ ] ;
152152
153153 // Create Angular compiler host options
154154 const hostOptions : AngularHostOptions = {
@@ -173,31 +173,50 @@ export function createCompilerPlugin(
173173 ( result . errors ??= [ ] ) . push ( ...errors ) ;
174174 }
175175 ( result . warnings ??= [ ] ) . push ( ...warnings ) ;
176- stylesheetResourceFiles . push ( ...resourceFiles ) ;
176+ additionalOutputFiles . push ( ...resourceFiles ) ;
177177 if ( stylesheetResult . metafile ) {
178- stylesheetMetafiles . push ( stylesheetResult . metafile ) ;
178+ additionalMetafiles . push ( stylesheetResult . metafile ) ;
179179 }
180180
181181 return contents ;
182182 } ,
183183 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 ,
197204 } ) ;
198205
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+ ) ;
201220 } ,
202221 } ;
203222
@@ -365,20 +384,20 @@ export function createCompilerPlugin(
365384 setupJitPluginCallbacks (
366385 build ,
367386 styleOptions ,
368- stylesheetResourceFiles ,
387+ additionalOutputFiles ,
369388 pluginOptions . loadResultCache ,
370389 ) ;
371390 }
372391
373392 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 ) ;
377396 }
378397
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 ) {
382401 result . metafile . inputs = { ...result . metafile . inputs , ...metafile . inputs } ;
383402 result . metafile . outputs = { ...result . metafile . outputs , ...metafile . outputs } ;
384403 }
0 commit comments