File tree Expand file tree Collapse file tree
packages/vite/src/node/server
playground/hmr-full-bundle-mode/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -343,6 +343,15 @@ export class BundledDev {
343343 )
344344 const result = await this . devEngine . compileEntry ( moduleId , clientId )
345345 this . pendingPayloadFilenames . add ( result . filename )
346+ // Serve the chunk's sourcemap, the same way an eager chunk's and an HMR
347+ // patch's maps are served. The chunk's relative `sourceMappingURL` resolves
348+ // against the URL it is imported from, `/@vite/lazy?...`, so register the map
349+ // under that directory for the reference to reach it.
350+ if ( result . sourcemapFilename && result . sourcemap ) {
351+ this . memoryFiles . set ( `@vite/${ result . sourcemapFilename } ` , {
352+ source : result . sourcemap ,
353+ } )
354+ }
346355 return {
347356 filename : result . filename ,
348357 code : result . code + payloadDeliveredAck ( result . filename ) ,
Original file line number Diff line number Diff line change @@ -317,8 +317,25 @@ if (isBuild) {
317317 } )
318318
319319 test ( 'lazy bundling' , async ( ) => {
320+ const responsePromise = page . waitForResponse ( / \/ @ v i t e \/ l a z y \? / )
320321 await page . click ( '#load-dynamic' )
321322 await expect . poll ( ( ) => page . textContent ( '.dynamic' ) ) . toBe ( 'loaded' )
323+
324+ // the lazy chunk names a `.map` file that only exists in memory; the dev
325+ // server has to register it, otherwise the reference 404s and the module
326+ // cannot be mapped back to its source. The reference is relative and a lazy
327+ // chunk is imported from `/@vite/lazy?...`, so it resolves under `/@vite/`.
328+ const response = await responsePromise
329+ const code = await response . text ( )
330+ const url = code . match ( / \/ \/ # s o u r c e M a p p i n g U R L = ( .+ ) $ / m) ?. [ 1 ]
331+ expect ( url ) . toMatch ( / ^ l a z y _ c o m p i l e _ \d + \. j s \. m a p $ / )
332+
333+ const mapResponse = await fetch ( new URL ( url ! , response . url ( ) ) )
334+ expect ( mapResponse . status ) . toBe ( 200 )
335+ const map = await mapResponse . json ( )
336+ expect ( map . version ) . toBe ( 3 )
337+ expect ( map . sources . some ( ( s : string ) => s . endsWith ( 'dynamic.js' ) ) ) . toBe ( true )
338+ expect ( map . mappings . length ) . toBeGreaterThan ( 0 )
322339 } )
323340
324341 // placed before `invalidate` on purpose: that test's cleanup restores
You can’t perform that action at this time.
0 commit comments