-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
CSS referenced assets are included even when the file is tree shaken #9073
Comments
This seems to be because CSS in Vite are side-effectful by default, so Rollup would proceed to render the chunk even if it's unused. We can't change that though since it would break many other tooling, though Vite supports the I also found another bug, which after using |
Update: I took another look at the issue today. The I'm not sure if there's a way for Rollup to skip transforming imports in dead code, I assume it doesn't treeshake after finished transforming/parsing a module. (Only during rendering?). So there isn't an easy fix on our side at the meantime, other that manually analyzing all assets emitted against the rendered chunks and delete them. About the |
I'm running into same result but the import is coming from JS file and not CSS. @bluwy do you think this is a different issue and has different root cause? https://stackblitz.com/edit/vite-unused-assets-tree-shake?file=main.js Here the However when the async function enableMocking() {
+ if (process.env.NODE_ENV === 'development') {
- if (process.env.NODE_ENV !== 'development') {
- return;
- }
const devTools = await import('./development-only');
console.log(devTools);
+ }
} The initial pattern is suggested by MSW documentation. I have MSW serving |
Describe the bug
When a vite build includes a css file conditionally bound to environment variables the referenced assets by the CSS file always end up in the assets output folder even when the CSS file itself which references them does not.
index.css
.env
index.js
Expected behavior:
index.css
androboto-regular.woff2
are not included in the build output folder.Actual behavior:
roboto-regular.woff2
is included in the build output folder.Reproduction
https://github.com/Csszabi98/css-tree-shake-asset-issue
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: