@@ -314,11 +314,24 @@ export default function VitePluginLibAssets(options: Options = {}): Plugin {
314
314
return map
315
315
} , { } as Record < string , string > )
316
316
317
- const updatedSourceMap = processAssetsInStyle ( bundleSourceMap )
317
+ /** Assets cached under watch mode also need to be processed by `processAssetsInStyle` and `processAssetsInImporters` #92 */
318
+ const cacheSourceMap = isBuildWatch
319
+ ? Object . values ( Object . fromEntries ( assetCache ) ) . reduce ( ( map , { fileName, source } ) => {
320
+ if ( fileName && source && ! outputBundle [ fileName ] )
321
+ map [ fileName ] = String ( source )
322
+ return map
323
+ } , { } as Record < string , string > )
324
+ : { }
325
+
326
+ const updatedSourceMap = processAssetsInStyle ( { ...bundleSourceMap , ...cacheSourceMap } )
318
327
const processedSourceMap = processAssetsInImporters ( updatedSourceMap )
319
328
320
329
Object . keys ( bundleSourceMap )
321
- . filter ( name => bundleSourceMap [ name ] !== processedSourceMap [ name ] )
330
+ /**
331
+ * Under watch mode, Vite won't resolve assets and this plugin wont't emit them,
332
+ * so they won't appear in the final output. We must trigger their emit manually.
333
+ */
334
+ . filter ( name => cacheSourceMap [ name ] || bundleSourceMap [ name ] !== processedSourceMap [ name ] )
322
335
. forEach ( ( name ) => {
323
336
const outputPath = path . posix . join ( outputDir , name )
324
337
const updated = processedSourceMap [ name ]
@@ -331,17 +344,6 @@ export default function VitePluginLibAssets(options: Options = {}): Plugin {
331
344
else if ( name . endsWith ( '.css' ) )
332
345
bundle . source = updated
333
346
} )
334
-
335
- /**
336
- * Under watch mode, Vite won't resolve assets and this plugin wont't emit them,
337
- * so they won't appear in the final output. We must trigger their emit manually.
338
- */
339
- if ( isBuildWatch ) {
340
- assetCache . forEach ( ( { fileName, source } ) => {
341
- if ( fileName && source && ! outputBundle [ fileName ] )
342
- fs . writeFileSync ( path . posix . join ( outputDir , fileName ) , source )
343
- } )
344
- }
345
347
} ,
346
348
}
347
349
}
0 commit comments