@@ -12,6 +12,7 @@ import {
1212 createDescriptor ,
1313 getDescriptor ,
1414 getPrevDescriptor ,
15+ getSrcDescriptor ,
1516 setSrcDescriptor ,
1617} from './utils/descriptorCache'
1718import {
@@ -434,13 +435,28 @@ async function genStyleCode(
434435 if ( descriptor . styles . length ) {
435436 for ( let i = 0 ; i < descriptor . styles . length ; i ++ ) {
436437 const style = descriptor . styles [ i ]
438+ let indexQuery = i
437439 if ( style . src ) {
438- await linkSrcToDescriptor (
439- style . src ,
440- descriptor ,
441- pluginContext ,
442- style . scoped ,
443- )
440+ const resolvedSrc =
441+ ( await pluginContext . resolve ( style . src , descriptor . filename ) ) ?. id ||
442+ style . src
443+ const alreadyDescriptor = getSrcDescriptor ( resolvedSrc , {
444+ scoped : style . scoped ,
445+ src : descriptor . id ,
446+ } )
447+
448+ if ( alreadyDescriptor ) {
449+ indexQuery = alreadyDescriptor . styles . findIndex (
450+ ( { scoped, src } ) => style . scoped === scoped && style . src === src ,
451+ )
452+ } else {
453+ await linkSrcToDescriptor (
454+ style . src ,
455+ descriptor ,
456+ pluginContext ,
457+ style . scoped ,
458+ )
459+ }
444460 }
445461 const src = style . src || descriptor . filename
446462 // do not include module in default query, since we use it to indicate
@@ -453,7 +469,7 @@ async function genStyleCode(
453469 : ''
454470 const directQuery = customElement ? `&inline` : ``
455471 const scopedQuery = style . scoped ? `&scoped=${ descriptor . id } ` : ``
456- const query = `?vue&type=style&index=${ i } ${ srcQuery } ${ directQuery } ${ scopedQuery } `
472+ const query = `?vue&type=style&index=${ indexQuery } ${ srcQuery } ${ directQuery } ${ scopedQuery } `
457473 const styleRequest = src + query + attrsQuery
458474 if ( style . module ) {
459475 if ( customElement ) {
0 commit comments