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

Commit

Permalink
feat: ignore empty style (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
yejinjian authored May 18, 2022
1 parent 0248eff commit 22410b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TestMultiplySrcImport from './src-import/TestMultiplySrcImport.vue'
import TestBlockSrcImport from './src-import/TestBlockSrcImport.vue'
import TestScopedCss from './css/TestScopedCss.vue'
import TestCssModules from './css/TestCssModules.vue'
import TestEmptyCss from './css/TestEmptyCss.vue'
import TestCustomBlock from './custom/TestCustomBlock.vue'
import TestHmr from './hmr/TestHmr.vue'
import TestAssets from './test-assets/TestAssets.vue'
Expand All @@ -18,6 +19,7 @@ export default {
TestScopedCss,
TestBlockSrcImport,
TestCssModules,
TestEmptyCss,
TestCustomBlock,
TestHmr,
TestAssets,
Expand All @@ -37,6 +39,7 @@ export default {
<TestScopedCss />
<TestCssModules />
<TestCustomBlock />
<TestEmptyCss />
<TestHmr />
<TestAssets />
<TestJsx />
Expand Down
11 changes: 11 additions & 0 deletions playground/css/TestEmptyCss.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
<h2>Empty CSS</h2>
<div>
&lt;style&gt;: empty style
</div>
</div>
</template>

<style scoped></style>
<style module></style>
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ async function genStyleRequest(
let stylesCode = ''
for (let i = 0; i < descriptor.styles.length; i++) {
const style = descriptor.styles[i]
if (!style.src && (!style.content || !style.content.trim()))
continue
const src = style.src || filename
const attrsQuery = attrsToQuery(style.attrs, 'css')
const srcQuery = style.src ? '&src' : ''
Expand Down
11 changes: 11 additions & 0 deletions test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ export function declareTests(isBuild: boolean) {
}
})

test('SFC empty style', async() => {
const el = await page.$$eval('style', (elements) => {
return elements.map((e) => {
return e.innerHTML?.trim()
}).filter((e) => {
return !e
})
})
expect(el).toHaveLength(0)
})

test('SFC <custom>', async() => {
expect(await getText('.custom-block')).toMatch('Custom Block')
expect(await getText('.custom-block-lang')).toMatch('Custom Block')
Expand Down

0 comments on commit 22410b8

Please sign in to comment.