@@ -237,20 +237,24 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
237237 } ,
238238 } ,
239239
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+ } ,
249256 }
250- } else {
251- return null
252- }
253- } ,
257+ : { } ) ,
254258
255259 generateBundle ( _ , bundle ) {
256260 // Remove empty entry point file
@@ -308,7 +312,7 @@ export async function fileToUrl(
308312 id : string ,
309313) : Promise < string > {
310314 const { environment } = pluginContext
311- if ( environment . config . command === 'serve' ) {
315+ if ( ! environment . config . isBundled ) {
312316 return fileToDevUrl ( environment , id )
313317 } else {
314318 return fileToBuiltUrl ( pluginContext , id )
@@ -457,7 +461,23 @@ async function fileToBuiltUrl(
457461 postfix = postfix . replace ( noInlineRE , '' ) . replace ( / ^ & / , '?' )
458462 }
459463
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+ }
461481 }
462482
463483 cache . set ( id , url )
0 commit comments