fix: remove unscopable global warning #1223
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1221. This removes the 'No scopable elements found in template' warning. While it's true that global styles are generally best avoided, they are sometimes necessary, and the advice in the FAQ to move them to another file doesn't add up, to me.
If you have component-specific global files and replace a
<style>
with animport './Foo.css'
you haven't improved Vite's ability to optimise the CSS, you've just added a new file and slightly increased the distance between the markup and the styles.If on the other hand you move all the styles to a
global.css
file, as the FAQ suggests, then in addition to increasing the distance between the markup and the styles, you've reduced Vite's ability to optimise stuff, because styles for components that aren't even imported will be present in the resulting bundle. (This would have been true in the first place for people using barrel files, but not everyone uses barrel files.)Either way, it's worse. Rather than being opinionated here we should just let component authors do what's right for them.