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