@@ -39,12 +39,12 @@ import {
39
39
transformJSCode ,
40
40
loadDeps ,
41
41
createModule ,
42
- formatErrorLineColumn
42
+ formatErrorLineColumn ,
43
+ loadModuleInternal ,
43
44
} from './tools'
44
45
45
46
import {
46
47
Options ,
47
- LoadModule ,
48
48
ModuleExport ,
49
49
CustomBlockCallback
50
50
} from './types'
@@ -76,12 +76,12 @@ const isProd : boolean = process.env.NODE_ENV === 'production';
76
76
* @internal
77
77
*/
78
78
79
- export async function createSFCModule ( source : string , filename : string , options : Options , loadModule : LoadModule ) : Promise < ModuleExport > {
79
+ export async function createSFCModule ( source : string , filename : string , options : Options ) : Promise < ModuleExport > {
80
80
81
81
const component = { } ;
82
82
83
83
84
- const { delimiters, moduleCache, compiledCache, pathHandlers : { resolve } , getFile , addStyle, log, additionalBabelPlugins = [ ] , customBlockHandler } = options ;
84
+ const { delimiters, moduleCache, compiledCache, getResource , addStyle, log, additionalBabelPlugins = [ ] , customBlockHandler } = options ;
85
85
86
86
const descriptor = sfc_parse ( {
87
87
source,
@@ -97,7 +97,7 @@ export async function createSFCModule(source : string, filename : string, option
97
97
98
98
// hack: asynchronously preloads the language processor before it is required by the synchronous preprocessCustomRequire() callback, see below
99
99
if ( descriptor . template && descriptor . template . lang )
100
- await loadModule ( descriptor . template . lang , options ) ;
100
+ await loadModuleInternal ( filename , descriptor . template . lang , options ) ;
101
101
102
102
103
103
const hasScoped = descriptor . styles . some ( e => e . scoped ) ;
@@ -109,7 +109,7 @@ export async function createSFCModule(source : string, filename : string, option
109
109
110
110
const compileTemplateOptions : TemplateCompileOptions = descriptor . template ? {
111
111
// hack, since sourceMap is not configurable an we want to get rid of source-map dependency. see genSourcemap
112
- source : descriptor . template . src ? ( await getFile ( resolve ( filename , descriptor . template . src ) ) ) . content : descriptor . template . content ,
112
+ source : descriptor . template . src ? ( await getResource ( filename , descriptor . template . src , options ) . getContent ( ) ) . content . toString ( ) : descriptor . template . content ,
113
113
filename,
114
114
compiler : vueTemplateCompiler as VueTemplateCompiler ,
115
115
compilerOptions : {
@@ -144,7 +144,7 @@ export async function createSFCModule(source : string, filename : string, option
144
144
145
145
// eg: https://github.com/vuejs/vue-loader/blob/v15.9.6/lib/index.js
146
146
147
- const src = descriptor . script . src ? ( await getFile ( resolve ( filename , descriptor . script . src ) ) ) . content : descriptor . script . content ;
147
+ const src = descriptor . script . src ? ( await getResource ( filename , descriptor . script . src , options ) . getContent ( ) ) . content . toString ( ) : descriptor . script . content ;
148
148
149
149
const [ depsList , transformedScriptSource ] = await withCache ( compiledCache , [ componentHash , src ] , async ( { preventCache } ) => {
150
150
@@ -188,8 +188,8 @@ export async function createSFCModule(source : string, filename : string, option
188
188
return [ depsList , transformedScript . code ] ;
189
189
} ) ;
190
190
191
- await loadDeps ( filename , depsList , options , loadModule ) ;
192
- Object . assign ( component , interopRequireDefault ( createModule ( filename , transformedScriptSource , options , loadModule ) . exports ) . default ) ;
191
+ await loadDeps ( filename , depsList , options ) ;
192
+ Object . assign ( component , interopRequireDefault ( createModule ( filename , transformedScriptSource , options ) . exports ) . default ) ;
193
193
}
194
194
195
195
@@ -232,14 +232,14 @@ export async function createSFCModule(source : string, filename : string, option
232
232
return await transformJSCode ( template . code , true , filename , options ) ;
233
233
} ) ;
234
234
235
- await loadDeps ( filename , templateDepsList , options , loadModule ) ;
236
- Object . assign ( component , createModule ( filename , templateTransformedSource , options , loadModule ) . exports ) ;
235
+ await loadDeps ( filename , templateDepsList , options ) ;
236
+ Object . assign ( component , createModule ( filename , templateTransformedSource , options ) . exports ) ;
237
237
}
238
238
239
239
240
240
for ( const descStyle of descriptor . styles ) {
241
241
242
- const src = descStyle . src ? ( await getFile ( resolve ( filename , descStyle . src ) ) ) . content : descStyle . content ;
242
+ const src = descStyle . src ? ( await getResource ( filename , descStyle . src , options ) . getContent ( ) ) . content . toString ( ) : descStyle . content ;
243
243
244
244
const style = await withCache ( compiledCache , [ componentHash , src , descStyle . lang ] , async ( { preventCache } ) => {
245
245
@@ -259,7 +259,7 @@ export async function createSFCModule(source : string, filename : string, option
259
259
260
260
// Vue2 doesn't support preprocessCustomRequire, so we have to preprocess manually
261
261
if ( descStyle . lang && processors [ descStyle . lang ] === undefined )
262
- processors [ descStyle . lang ] = await loadModule ( descStyle . lang , options ) as StylePreprocessor ;
262
+ processors [ descStyle . lang ] = await loadModuleInternal ( filename , descStyle . lang , options ) as StylePreprocessor ;
263
263
264
264
const compiledStyle = await sfc_compileStyleAsync ( compileStyleOptions ) ;
265
265
if ( compiledStyle . errors . length ) {
0 commit comments