1import esbuild from 'esbuild'2import { appCfgCtx, getAppCfg} from "../k8sF/ctxF/appCfgCtxF.mts"3import { getReqPubEnvItem } from '../../serverF/getReqPubEnvItemF.mts'4import { pathDownJoin } from "../../serverF/pathF.mts"5import { ptDir } from '../../serverF/ptDirF.mts'7export const doBuildSw = async ({doWatch}: {doWatch?: boolean}={}) => {10 const ptOutPath = pathDownJoin(appPath!, 'public', getReqPubEnvItem('builtSwFilename') as string)11 const ptInPath = pathDownJoin(appPath!, 'entrypoints', 'sw.mjs')13 const absOutPath = pathDownJoin(ptDir, ptOutPath)14 const buildOptions = {15 entryPoints: [16 pathDownJoin(ptDir, ptInPath)17 ],18 bundle: true,19 outfile: absOutPath,20 // outdir: outPath,21 format: 'iife' as const,22 jsx: 'automatic' as const,23 minify: true,24 }26 await esbuild.build(buildOptions)27 console.log('builtsw', ptInPath, '->', ptOutPath)29 if (doWatch) {30 const ctx = await esbuild.context(buildOptions)31 await ctx.watch()32 console.log('Watching for changes...')33 }34}