@@ -77,7 +77,7 @@ export async function createSFCModule(source : string, filename : string, option
77
77
const component = { } ;
78
78
79
79
80
- const { moduleCache, compiledCache, addStyle, log, additionalBabelPlugins = [ ] , customBlockHandler } = options ;
80
+ const { moduleCache, compiledCache, pathHandlers : { resolve } , getFile , addStyle, log, additionalBabelPlugins = [ ] , customBlockHandler } = options ;
81
81
82
82
// vue-loader next: https://github.com/vuejs/vue-loader/blob/next/src/index.ts#L91
83
83
const descriptor = sfc_parse ( {
@@ -106,7 +106,7 @@ export async function createSFCModule(source : string, filename : string, option
106
106
107
107
const compileTemplateOptions : TemplateCompileOptions = descriptor . template ? {
108
108
// hack, since sourceMap is not configurable an we want to get rid of source-map dependency. see genSourcemap
109
- source : descriptor . template . content ,
109
+ source : descriptor . template . src ? ( await getFile ( resolve ( filename , descriptor . template . src ) ) ) . content : descriptor . template . content ,
110
110
filename,
111
111
compiler : vueTemplateCompiler as VueTemplateCompiler ,
112
112
compilerOptions : {
@@ -136,13 +136,15 @@ export async function createSFCModule(source : string, filename : string, option
136
136
137
137
// eg: https://github.com/vuejs/vue-loader/blob/v15.9.6/lib/index.js
138
138
139
- const [ depsList , transformedScriptSource ] = await withCache ( compiledCache , [ componentHash , descriptor . script . content ] , async ( { preventCache } ) => {
139
+ const src = descriptor . script . src ? ( await getFile ( resolve ( filename , descriptor . script . src ) ) ) . content : descriptor . script . content ;
140
+
141
+ const [ depsList , transformedScriptSource ] = await withCache ( compiledCache , [ componentHash , src ] , async ( { preventCache } ) => {
140
142
141
143
const babelParserPlugins : babel_ParserPlugin [ ] = [ ] ;
142
144
143
145
let ast : t . File
144
146
try {
145
- ast = babel_parse ( descriptor . script . content , {
147
+ ast = babel_parse ( src , {
146
148
// doc: https://babeljs.io/docs/en/babel-parser#options
147
149
// if: https://github.com/babel/babel/blob/main/packages/babel-parser/typings/babel-parser.d.ts#L24
148
150
plugins : [
@@ -161,7 +163,7 @@ export async function createSFCModule(source : string, filename : string, option
161
163
const depsList = parseDeps ( ast ) ;
162
164
163
165
// doc: https://babeljs.io/docs/en/babel-core#transformfromastasync
164
- const transformedScript = await babel_transformFromAstAsync ( ast , descriptor . script . content , {
166
+ const transformedScript = await babel_transformFromAstAsync ( ast , src , {
165
167
sourceMaps : genSourcemap , // https://babeljs.io/docs/en/options#sourcemaps
166
168
plugins : [ // https://babeljs.io/docs/en/options#plugins
167
169
babelPluginTransformModulesCommonjs , // https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#options
@@ -183,7 +185,7 @@ export async function createSFCModule(source : string, filename : string, option
183
185
if ( descriptor . template !== null ) {
184
186
// compiler-sfc src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileTemplate.ts#L39
185
187
// compileTemplate eg: https://github.com/vuejs/vue-loader/blob/next/src/templateLoader.ts#L33
186
- const [ templateDepsList , templateTransformedSource ] = await withCache ( compiledCache , [ componentHash , descriptor . template . content ] , async ( { preventCache } ) => {
188
+ const [ templateDepsList , templateTransformedSource ] = await withCache ( compiledCache , [ componentHash , compileTemplateOptions . source ] , async ( { preventCache } ) => {
187
189
188
190
const template = sfc_compileTemplate ( compileTemplateOptions ) ;
189
191
// "@vue/component-compiler-utils" does NOT assume any module system, and expose render in global scope.
@@ -227,11 +229,13 @@ export async function createSFCModule(source : string, filename : string, option
227
229
228
230
for ( const descStyle of descriptor . styles ) {
229
231
230
- const style = await withCache ( compiledCache , [ componentHash , descStyle . content ] , async ( { preventCache } ) => {
232
+ const src = descStyle . src ? ( await getFile ( resolve ( filename , descStyle . src ) ) ) . content : descStyle . content ;
233
+
234
+ const style = await withCache ( compiledCache , [ componentHash , src , descStyle . lang ] , async ( { preventCache } ) => {
231
235
// src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileStyle.ts#L70
232
236
233
237
const compileStyleOptions : StyleCompileOptions = {
234
- source : descStyle . content ,
238
+ source : src ,
235
239
filename,
236
240
id : scopeId ,
237
241
scoped : descStyle . scoped ,
@@ -254,7 +258,7 @@ export async function createSFCModule(source : string, filename : string, option
254
258
preventCache ( ) ;
255
259
for ( const err of compiledStyle . errors ) {
256
260
257
- log ?.( 'error' , 'SFC style' , formatError ( err , filename , descStyle . content ) ) ;
261
+ log ?.( 'error' , 'SFC style' , formatError ( err , filename , source ) ) ;
258
262
}
259
263
}
260
264
0 commit comments