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

feat: ignore empty style #193

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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