@@ -238,20 +238,24 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
238238 } ,
239239 } ,
240240
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+ } ,
250257 }
251- } else {
252- return null
253- }
254- } ,
258+ : { } ) ,
255259
256260 generateBundle ( _ , bundle ) {
257261 // Remove empty entry point file
@@ -309,7 +313,7 @@ export async function fileToUrl(
309313 id : string ,
310314) : Promise < string > {
311315 const { environment } = pluginContext
312- if ( environment . config . command === 'serve' ) {
316+ if ( ! environment . config . isBundled ) {
313317 return fileToDevUrl ( environment , id )
314318 } else {
315319 return fileToBuiltUrl ( pluginContext , id )
@@ -458,7 +462,23 @@ async function fileToBuiltUrl(
458462 postfix = postfix . replace ( noInlineRE , '' ) . replace ( / ^ & / , '?' )
459463 }
460464
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+ }
462482 }
463483
464484 cache . set ( id , url )
0 commit comments