Skip to content

Conversation

yejinjian
Copy link

Prevents generation of empty style file when use

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

// 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