@@ -39,6 +39,7 @@ import {
3939 LoadingType ,
4040 PathContext ,
4141 AbstractPath ,
42+ File ,
4243} from './types'
4344
4445import { createSFCModule } from './createSFCModule'
@@ -278,19 +279,16 @@ export async function loadModuleInternal(pathCx : PathContext, options : Options
278279 return moduleCache [ id ] = module ;
279280 }
280281
281- const { content, type } = await getContent ( ) ;
282-
283- if ( typeof content !== 'string' )
284- throw new TypeError ( `Invalid module content (${ path } ): ${ content } ` ) ;
282+ const { getContentData, type } = await getContent ( ) ;
285283
286284 // note: null module is accepted
287285 let module : ModuleExport | undefined | null = undefined ;
288286
289287 if ( handleModule !== undefined )
290- module = await handleModule ( type , content , path , options ) ;
288+ module = await handleModule ( type , getContentData , path , options ) ;
291289
292290 if ( module === undefined )
293- module = await defaultHandleModule ( type , content , path , options ) ;
291+ module = await defaultHandleModule ( type , getContentData , path , options ) ;
294292
295293 if ( module === undefined )
296294 throw new TypeError ( `Unable to handle ${ type } files (${ path } )` ) ;
@@ -369,12 +367,12 @@ export async function loadDeps(refPath : AbstractPath, deps : AbstractPath[], op
369367/**
370368 * Default implementation of handleModule
371369 */
372- async function defaultHandleModule ( type : string , source : string , path : AbstractPath , options : Options ) : Promise < ModuleExport | null > {
370+ async function defaultHandleModule ( type : string , getContentData : File [ 'getContentData' ] , path : AbstractPath , options : Options ) : Promise < ModuleExport | null > {
373371
374372 switch ( type ) {
375- case '.vue' : return createSFCModule ( source . toString ( ) , path , options ) ;
376- case '.js' : return createJSModule ( source . toString ( ) , false , path , options ) ;
377- case '.mjs' : return createJSModule ( source . toString ( ) , true , path , options ) ;
373+ case '.vue' : return createSFCModule ( ( await getContentData ( false ) ) as string , path , options ) ;
374+ case '.js' : return createJSModule ( ( await getContentData ( false ) ) as string , false , path , options ) ;
375+ case '.mjs' : return createJSModule ( ( await getContentData ( false ) ) as string , true , path , options ) ;
378376 }
379377
380378 return undefined ;
0 commit comments