Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: ignore empty style block
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Nov 30, 2020
1 parent faeab3b commit 0dd5e0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
*.local
yarn-error.log
.idea/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"vue-template-compiler": "^2.6.11"
},
"peerDependencies": {
"vite": ">=1.0.0-rc.4"
"vite": ">=1.0.0-rc.13"
},
"devDependencies": {
"@types/fs-extra": "^9.0.1",
Expand Down
34 changes: 18 additions & 16 deletions src/serverPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,24 @@ async function parseSFC(
let stylesCode = ``
let hasScoped
if (descriptor.styles.length) {
descriptor.styles.forEach((s, i) => {
const styleRequest = publicPath + `?type=style&index=${i}`
if (s.scoped) hasScoped = true
if (s.module) {
const styleVar = `__style${i}`
const moduleName = typeof s.module === 'string' ? s.module : '$style'
stylesCode += `\nimport ${styleVar} from ${JSON.stringify(
styleRequest + '&module'
)}`
stylesCode += `\n__cssModules[${JSON.stringify(
moduleName
)}] = ${styleVar}`
} else {
stylesCode += `\nimport ${JSON.stringify(styleRequest)}`
}
})
descriptor.styles
.filter((s) => !!s.content.trim())
.forEach((s, i) => {
const styleRequest = publicPath + `?type=style&index=${i}`
if (s.scoped) hasScoped = true
if (s.module) {
const styleVar = `__style${i}`
const moduleName = typeof s.module === 'string' ? s.module : '$style'
stylesCode += `\nimport ${styleVar} from ${JSON.stringify(
styleRequest + '&module'
)}`
stylesCode += `\n__cssModules[${JSON.stringify(
moduleName
)}] = ${styleVar}`
} else {
stylesCode += `\nimport ${JSON.stringify(styleRequest)}`
}
})
}

let code =
Expand Down

0 comments on commit 0dd5e0a

Please sign in to comment.