import type * as d from '../../declarations' ; import { generateServiceWorker } from '../service-worker/generate-sw' ; import { isOutputTargetWww } from './output-utils' ; export const outputServiceWorkers = async ( config , buildCtx ) => { const wwwServiceOutputs = config . outputTargets . filter ( isOutputTargetWww ) . filter ( ( o ) => typeof o . indexHtml === 'string' && ! ! o . serviceWorker ) ; if ( wwwServiceOutputs . length === 0 || config . sys . lazyRequire == null ) { return ; } const diagnostics = await config . sys . lazyRequire . ensure ( config . rootDir , [ 'workbox-build' ] ) ; if ( diagnostics . length > 0 ) { buildCtx . diagnostics . push ( ... diagnostics ) ; } else { const workbox = config . sys . lazyRequire . require ( config . rootDir , 'workbox-build' ) ; await Promise . all ( wwwServiceOutputs . map ( ( outputTarget ) => generateServiceWorker ( config , buildCtx , workbox , outputTarget ) ) ) ; } } ;