@@ -306,20 +306,27 @@ const modifyBuiltFiles = {
306306 // Modify the redirects file last
307307 await modifyRedirects ( )
308308
309- // create a CSS config file we will use to get the proper CSS filename
310- const indexCssFile = Object . keys ( metafile . outputs ) . find ( file => file . endsWith ( '.css' ) && file . includes ( 'app' ) )
311- if ( indexCssFile ) {
312- const cssConfigContent = `export const CSS_FILENAME = '${ path . basename ( indexCssFile ) } '`
313- await fs . writeFile ( path . resolve ( 'dist/ipfs-sw-css-config.js' ) , cssConfigContent )
314- console . log ( `Created dist/ipfs-sw-css-config.js with CSS filename: ${ path . basename ( indexCssFile ) } ` )
315- }
309+ for ( const [ file , meta ] of Object . entries ( metafile . outputs ) ) {
310+ if ( meta . entryPoint != null ) {
311+ console . info ( meta . entryPoint , '->' , file )
312+ }
316313
317- // create an app chunk config file we will use to get the proper app chunk filename for importing all the UI dynamically
318- const appChunkFile = Object . keys ( metafile . outputs ) . find ( file => file . endsWith ( '.js' ) && file . includes ( 'app' ) )
319- if ( appChunkFile ) {
320- const appConfigContent = `export const APP_FILENAME = '${ path . basename ( appChunkFile ) } '`
321- await fs . writeFile ( path . resolve ( 'dist/ipfs-sw-app-config.js' ) , appConfigContent )
322- console . log ( `Created dist/ipfs-sw-app-config.js with app chunk filename: ${ path . basename ( appChunkFile ) } ` )
314+ // create an app chunk config file we will use to get the proper app
315+ // chunk filename for importing all the UI dynamically
316+ if ( meta . entryPoint === 'src/ui/index.tsx' ) {
317+ const appConfigContent = `export const APP_FILENAME = '${ path . basename ( file ) } '`
318+ await fs . writeFile ( path . resolve ( 'dist/ipfs-sw-app-config.js' ) , appConfigContent )
319+ console . log ( `Created dist/ipfs-sw-app-config.js with app chunk filename: ${ path . basename ( file ) } ` )
320+ }
321+
322+ // create a CSS config file we will use to get the proper CSS filename
323+ // TODO: this is too fragile, it only works because there is a only one
324+ // css file in the output
325+ if ( file . endsWith ( '.css' ) ) {
326+ const cssConfigContent = `export const CSS_FILENAME = '${ path . basename ( file ) } '`
327+ await fs . writeFile ( path . resolve ( 'dist/ipfs-sw-css-config.js' ) , cssConfigContent )
328+ console . log ( `Created dist/ipfs-sw-css-config.js with CSS filename: ${ path . basename ( file ) } ` )
329+ }
323330 }
324331 } )
325332 }
@@ -369,7 +376,13 @@ export const buildOptions = {
369376 format : 'esm' ,
370377 entryNames : 'ipfs-sw-[name]-[hash]' ,
371378 assetNames : 'ipfs-sw-[name]-[hash]' ,
372- plugins : [ replaceImports , renameSwPlugin , updateVersions , modifyBuiltFiles , excludeFilesPlugin ( [ '.eot?#iefix' , '.otf' , '.woff' , '.woff2' ] ) ]
379+ plugins : [
380+ replaceImports ,
381+ renameSwPlugin ,
382+ updateVersions ,
383+ modifyBuiltFiles ,
384+ excludeFilesPlugin ( [ '.eot?#iefix' , '.otf' , '.woff' , '.woff2' ] )
385+ ]
373386}
374387
375388const ctx = await esbuild . context ( buildOptions )
0 commit comments