Open tomolenet opened 10 months ago
There was an attempt to fix this at https://github.com/sveltejs/vite-plugin-svelte/pull/760 but there's a Vite bug blocking marking CSS files as side-effect-less through moduleSideEffects
. I'm not sure what the fix is, but perhaps we can use this issue to track fixing this.
Thank you for the introduction. We would be very grateful for a solution and I am willing to support if I can.
Describe the bug
We want to use the svelte kit library (building based on vite) configuration to build a component library that we integrate into a svelte kit app. When we import components as modules. For example like this:
Then we get in the build files all css stylings of other components that are not used or imported in the application. If the components are imported explicitly, there are no unwanted stylings in the build files.
Reproduction
https://github.com/tomolenet/svelte-kit-treeshaking
Steps to reproduce
In
packages/svelte-kit-app
we use thepackages/svelte-kit-library
insrc/routes/+page.svelte
. First use the module import in line 7.Now check the output
packages/svelte-kit-app/.svelte-kit
. If you search for.unwanted
which is styling of theUnwanted
component ofpackages/svelte-kit-library
you realize that styling exists in the build result. However, we have not imported the component at any point in the project.Now change the import statement and use explicit import in line 10.
Now the
.unwanted
class is no longer included in the build. It seems that the tree shaking does not work correctly at this point.System Info
Used Package Manager
npm
Logs
No response
Validations