@@ -25,7 +25,10 @@ class ModernModePlugin {
2525 // get stats, write to disk
2626 await fs . ensureDir ( this . targetDir )
2727 const htmlName = path . basename ( data . plugin . options . filename )
28- const tempFilename = path . join ( this . targetDir , `legacy-assets-${ htmlName } .json` )
28+ // Watch out for output files in sub directories
29+ const htmlPath = path . dirname ( data . plugin . options . filename )
30+ const tempFilename = path . join ( this . targetDir , htmlPath , `legacy-assets-${ htmlName } .json` )
31+ await fs . mkdirp ( path . dirname ( tempFilename ) )
2932 await fs . writeFile ( tempFilename , JSON . stringify ( data . body ) )
3033 cb ( )
3134 } )
@@ -52,7 +55,9 @@ class ModernModePlugin {
5255
5356 // inject links for legacy assets as <script nomodule>
5457 const htmlName = path . basename ( data . plugin . options . filename )
55- const tempFilename = path . join ( this . targetDir , `legacy-assets-${ htmlName } .json` )
58+ // Watch out for output files in sub directories
59+ const htmlPath = path . dirname ( data . plugin . options . filename )
60+ const tempFilename = path . join ( this . targetDir , htmlPath , `legacy-assets-${ htmlName } .json` )
5661 const legacyAssets = JSON . parse ( await fs . readFile ( tempFilename , 'utf-8' ) )
5762 . filter ( a => a . tagName === 'script' && a . attributes )
5863 legacyAssets . forEach ( a => { a . attributes . nomodule = '' } )
0 commit comments