@@ -237,20 +237,24 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
237
237
} ,
238
238
} ,
239
239
240
- renderChunk ( code , chunk , opts ) {
241
- const s = renderAssetUrlInJS ( this , chunk , opts , code )
242
-
243
- if ( s ) {
244
- return {
245
- code : s . toString ( ) ,
246
- map : this . environment . config . build . sourcemap
247
- ? s . generateMap ( { hires : 'boundary' } )
248
- : null ,
240
+ ...( config . command === 'build'
241
+ ? {
242
+ renderChunk ( code , chunk , opts ) {
243
+ const s = renderAssetUrlInJS ( this , chunk , opts , code )
244
+
245
+ if ( s ) {
246
+ return {
247
+ code : s . toString ( ) ,
248
+ map : this . environment . config . build . sourcemap
249
+ ? s . generateMap ( { hires : 'boundary' } )
250
+ : null ,
251
+ }
252
+ } else {
253
+ return null
254
+ }
255
+ } ,
249
256
}
250
- } else {
251
- return null
252
- }
253
- } ,
257
+ : { } ) ,
254
258
255
259
generateBundle ( _ , bundle ) {
256
260
// Remove empty entry point file
@@ -308,7 +312,7 @@ export async function fileToUrl(
308
312
id : string ,
309
313
) : Promise < string > {
310
314
const { environment } = pluginContext
311
- if ( environment . config . command === 'serve' ) {
315
+ if ( ! environment . config . isBundled ) {
312
316
return fileToDevUrl ( environment , id )
313
317
} else {
314
318
return fileToBuiltUrl ( pluginContext , id )
@@ -457,7 +461,23 @@ async function fileToBuiltUrl(
457
461
postfix = postfix . replace ( noInlineRE , '' ) . replace ( / ^ & / , '?' )
458
462
}
459
463
460
- url = `__VITE_ASSET__${ referenceId } __${ postfix ? `$_${ postfix } __` : `` } `
464
+ if ( environment . config . experimental . fullBundleMode ) {
465
+ const outputFilename = pluginContext . getFileName ( referenceId )
466
+ const outputUrl = toOutputFilePathInJS (
467
+ environment ,
468
+ outputFilename ,
469
+ 'asset' ,
470
+ 'assets/dummy.js' ,
471
+ 'js' ,
472
+ ( ) => {
473
+ throw new Error ( 'unreachable' )
474
+ } ,
475
+ )
476
+ if ( typeof outputUrl === 'object' ) throw new Error ( 'not supported' )
477
+ url = outputUrl
478
+ } else {
479
+ url = `__VITE_ASSET__${ referenceId } __${ postfix ? `$_${ postfix } __` : `` } `
480
+ }
461
481
}
462
482
463
483
cache . set ( id , url )
0 commit comments