@@ -20,10 +20,11 @@ export async function transformVue(code: string, options?: Options) {
2020 descriptor : { template, styles } ,
2121 errors,
2222 } = parse ( code )
23- if ( errors . length || ! template || ! styles . length )
23+ if ( errors . length || ! template )
2424 return code
2525 // transform inline-style
2626 code = transformInlineStyle ( code , isJsx , isRem )
27+
2728 // transform @media 注:transformBack是将@media中内容用一个占位符替换等到transformCss处理完将结果还原回去
2829 const [ transferMediaCode , transformBack ] = await transformMedia (
2930 code ,
@@ -32,20 +33,22 @@ export async function transformVue(code: string, options?: Options) {
3233 )
3334
3435 code = transferMediaCode
35- // transform class
36- const {
37- attrs : { scoped } ,
38- content : style ,
39- lang = 'css' ,
40- } = styles [ 0 ]
36+ if ( styles . length ) {
37+ // transform class
38+ const {
39+ attrs : { scoped } ,
40+ content : style ,
41+ lang = 'css' ,
42+ } = styles [ 0 ]
4143
42- const css = await compilerCss ( style , lang as CssType , filepath , globalCss )
43- if ( css ) {
44- // 能被正确编译解析的css
45- code = code . replace ( style , `\n${ css } \n` ) . replace ( ` lang="${ lang } "` , '' )
46- // 只针对scoped css处理
47- if ( scoped )
48- code = await transformCss ( css , code , '' , isJsx , filepath , isRem )
44+ const css = await compilerCss ( style , lang as CssType , filepath , globalCss )
45+ if ( css ) {
46+ // 能被正确编译解析的css
47+ code = code . replace ( style , `\n${ css } \n` ) . replace ( ` lang="${ lang } "` , '' )
48+ // 只针对scoped css处理
49+ if ( scoped )
50+ code = await transformCss ( css , code , '' , isJsx , filepath , isRem )
51+ }
4952 }
5053
5154 // 还原@media 未匹配到的class
0 commit comments