@@ -80,7 +80,8 @@ export async function createSFCModule(source : string, filename : AbstractPath,
8080 additionalBabelPlugins = { } ,
8181 customBlockHandler,
8282 devMode = false ,
83- createCJSModule
83+ createCJSModule,
84+ processStyles,
8485 } = options ;
8586
8687 // vue-loader next: https://github.com/vuejs/vue-loader/blob/next/src/index.ts#L91
@@ -240,21 +241,27 @@ export async function createSFCModule(source : string, filename : AbstractPath,
240241
241242 for ( const descStyle of descriptor . styles ) {
242243
243- // hack: asynchronously preloads the language processor before it is required by the synchronous preprocessCustomRequire() callback, see below
244- if ( descStyle . lang )
245- await loadModuleInternal ( { refPath : filename , relPath : descStyle . lang } , options ) ;
246-
247- const src = descStyle . src ? ( await ( await getResource ( { refPath : filename , relPath : descStyle . src } , options ) . getContent ( ) ) . getContentData ( false ) ) as string : descStyle . content ;
248-
244+ const srcRaw = descStyle . src ? ( await ( await getResource ( { refPath : filename , relPath : descStyle . src } , options ) . getContent ( ) ) . getContentData ( false ) ) as string : descStyle . content ;
245+
249246 const style =
250247 await withCache (
251248 compiledCache ,
252249 [
253250 componentHash ,
254- src
251+ srcRaw ,
252+ descStyle . lang
255253 ] ,
256254 async ( { preventCache } ) => {
257255
256+ const src = processStyles !== undefined ? await processStyles ( srcRaw , descStyle . lang , filename , options ) : srcRaw ;
257+
258+ if ( src === undefined )
259+ preventCache ( ) ;
260+
261+ // hack: asynchronously preloads the language processor before it is required by the synchronous preprocessCustomRequire() callback, see below
262+ if ( processStyles === undefined && descStyle . lang !== undefined )
263+ await loadModuleInternal ( { refPath : filename , relPath : descStyle . lang } , options ) ;
264+
258265 // src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileStyle.ts#L70
259266 const compiledStyle = await sfc_compileStyleAsync ( {
260267 filename : descriptor . filename ,
@@ -263,8 +270,10 @@ export async function createSFCModule(source : string, filename : AbstractPath,
263270 id : scopeId ,
264271 scoped : descStyle . scoped ,
265272 trim : true ,
266- preprocessLang : descStyle . lang as PreprocessLang ,
267- preprocessCustomRequire : id => moduleCache [ id ] ,
273+ ...processStyles === undefined ? {
274+ preprocessLang : descStyle . lang as PreprocessLang ,
275+ preprocessCustomRequire : id => moduleCache [ id ] ,
276+ } : { } ,
268277 } ) ;
269278
270279 if ( compiledStyle . errors . length ) {
0 commit comments