You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are manually calling defineComponent(), which makes it look like it has side effects to the bundler. This is unnecessary if you are just defining a component name - just do export default { name: '...' }.
Also, since 3.2.24 SFCs using <script setup> automatically infers name option based on filename so it's not even necessary to use a separate <script> block.
If you do need defineComponent() for whatever reason, mark it as side-effect free with the pure annotation (this works in both webpack and vite):
Vue version
3.2+
Link to minimal reproduction
https://github.com/0x009922/vue-sfc-tree-shaking-issue
Steps to reproduce
Create a component:
Re-export it from a module with other stuff:
Import other stuff in a bundler entry:
Bundle it (I use Vite's library mode)
What is expected?
Bundler output:
What is actually happening?
Bundled file weight is 42kb with the whole Vue.
System Info
Any additional comments?
If you remove
lang=ts
and leave just 2<script>
blocks, then tree-shaking works. But even in that case the bundle output has a dirt:Context: we have a component library, and we use
lang=ts
for components. Due to this bug, we can't tree-shake unused stuff from our library.Maybe related? #2860
The text was updated successfully, but these errors were encountered: