Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore empty style when compiler #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yejinjian
Copy link

Prevents generation of empty style file when use

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

@@ -39,7 +39,7 @@ export async function transformMain(

// 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())
Copy link

@thebanjomatic thebanjomatic Jan 13, 2023

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants