Skip to content
This repository was archived by the owner on May 19, 2026. It is now read-only.

feat: ignore empty style when compiler - #58

Open
yejinjian wants to merge 1 commit into
vitejs:mainfrom
yejinjian:main
Open

feat: ignore empty style when compiler#58
yejinjian wants to merge 1 commit into
vitejs:mainfrom
yejinjian:main

Conversation

@yejinjian

Copy link
Copy Markdown

Prevents generation of empty style file when use

<styles scope></style>
<styles module></style>

Comment thread src/main.ts
// feature information
const hasScoped = descriptor.styles.some(s => s.scoped)
const hasCssModules = descriptor.styles.some(s => s.module)
const hasCssModules = descriptor.styles.some(s => s.module && !!s.content && !!s.content.trim())

@thebanjomatic thebanjomatic Jan 13, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a trimmed copy of the string to see if it is empty isn't a very fast (or memory efficient) way to check to see if the string is only whitespace. The current approach you are using appears to be about 40% slower than:

const hasNonWhitespaceContent = (content: string | undefined) => !!content && /\S/.test(content)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants