-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Treeshake unused Astro scoped styles #10291
Conversation
🦋 Changeset detectedLatest commit: 5fd71e7 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const cssDeps: CompileCssResult['dependencies'][] = []; | ||
const cssPartialCompileResults: PartialCompileCssResult[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I refactored this from string[][]
to { ... dependencies: string[] }[]
because I needed to keep an extra isGlobal
metadata whenever preprocessing is called.
await import('../components/Three.astro'); | ||
await import('../components/Three.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR caused this test to fail because the Three.astro
component was imported but it's never used, hence the scoped styles in Three.astro
weren't injected. Previously it was testing if the scoped styles were injected which I don't think it's quite right.
This test comes from #6176, so to stay true to what it's testing, I changed it to a .js
file so that the CSS is no longer scoped.
e112e38
to
758663f
Compare
!preview treeshake-scoped-css |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it!
Changes
Unused scoped styles from Astro components are removed by checking if the main Astro module (that owns the scoped styles) is also removed/treeshaken. The PR copies some code from vitejs/vite#16058 to fix this at the meantime.
There's currently a tradeoff with this approach (vitejs/vite#16058 (comment)), but it should be better than before, and also it could be better.
Testing
Added a test. Also tested on a starlight project.
Docs
n/a. internal improvement