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

Commit 22410b8

Browse files
authored
feat: ignore empty style (#193)
1 parent 0248eff commit 22410b8

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

playground/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TestMultiplySrcImport from './src-import/TestMultiplySrcImport.vue'
33
import TestBlockSrcImport from './src-import/TestBlockSrcImport.vue'
44
import TestScopedCss from './css/TestScopedCss.vue'
55
import TestCssModules from './css/TestCssModules.vue'
6+
import TestEmptyCss from './css/TestEmptyCss.vue'
67
import TestCustomBlock from './custom/TestCustomBlock.vue'
78
import TestHmr from './hmr/TestHmr.vue'
89
import TestAssets from './test-assets/TestAssets.vue'
@@ -18,6 +19,7 @@ export default {
1819
TestScopedCss,
1920
TestBlockSrcImport,
2021
TestCssModules,
22+
TestEmptyCss,
2123
TestCustomBlock,
2224
TestHmr,
2325
TestAssets,
@@ -37,6 +39,7 @@ export default {
3739
<TestScopedCss />
3840
<TestCssModules />
3941
<TestCustomBlock />
42+
<TestEmptyCss />
4043
<TestHmr />
4144
<TestAssets />
4245
<TestJsx />

playground/css/TestEmptyCss.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
<h2>Empty CSS</h2>
4+
<div>
5+
&lt;style&gt;: empty style
6+
</div>
7+
</div>
8+
</template>
9+
10+
<style scoped></style>
11+
<style module></style>

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ async function genStyleRequest(
283283
let stylesCode = ''
284284
for (let i = 0; i < descriptor.styles.length; i++) {
285285
const style = descriptor.styles[i]
286+
if (!style.src && (!style.content || !style.content.trim()))
287+
continue
286288
const src = style.src || filename
287289
const attrsQuery = attrsToQuery(style.attrs, 'css')
288290
const srcQuery = style.src ? '&src' : ''

test/e2e.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ export function declareTests(isBuild: boolean) {
100100
}
101101
})
102102

103+
test('SFC empty style', async() => {
104+
const el = await page.$$eval('style', (elements) => {
105+
return elements.map((e) => {
106+
return e.innerHTML?.trim()
107+
}).filter((e) => {
108+
return !e
109+
})
110+
})
111+
expect(el).toHaveLength(0)
112+
})
113+
103114
test('SFC <custom>', async() => {
104115
expect(await getText('.custom-block')).toMatch('Custom Block')
105116
expect(await getText('.custom-block-lang')).toMatch('Custom Block')

0 commit comments

Comments
 (0)