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
Vite is not tree-shaking unused Vue 3 components from a consuming Vue 3 application. The Vue 3 component library is built with Vite, configured in "library mode", and imported into a vanilla Vue 3 application. The Vue 3 components from the library use the defineComponent type helper.
It was unclear whether this should be filed in vuejs/core or here since theoretically Vite should be handling this.
There doesn't seem to be any problem with tree shaking when using the <script setup/> syntactic sugar or Options API to define a component. The problem seems isolated to using defineComponent. You can work around this by prefixing /*@__PURE__*/ to defineComponent, i.e.
However, according to the docs, this shouldn't be required when using Vite.
Note this is not necessary if you are using Vite, because Rollup (the underlying production bundler used by Vite) is smart enough to determine that defineComponent() is in fact side-effect-free without the need for manual annotations.
### Used Package Manager
npm
### Logs
_No response_
### Validations
- [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitejs.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to [vuejs/core](https://github.com/vuejs/core) instead.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
The text was updated successfully, but these errors were encountered:
Describe the bug
Vite is not tree-shaking unused Vue 3 components from a consuming Vue 3 application. The Vue 3 component library is built with Vite, configured in "library mode", and imported into a vanilla Vue 3 application. The Vue 3 components from the library use the
defineComponent
type helper.It was unclear whether this should be filed in
vuejs/core
or here since theoretically Vite should be handling this.Reproduction
https://github.com/HeavyMedl/library-not-tree-shakeable
Steps to reproduce
Inspect the bundle produced by Vite in
dist/assets
.What is expected?
The bundle should only contain
vue-library/src/components/ComponentA.vue
code, withvue-library/src/components/ComponentB.vue
code tree shaken outWhat is happening?
vue-library/src/components/ComponentB.vue
code is built into the bundle.Any additional comments?
There doesn't seem to be any problem with tree shaking when using the
<script setup/>
syntactic sugar or Options API to define a component. The problem seems isolated to usingdefineComponent
. You can work around this by prefixing/*@__PURE__*/
todefineComponent
, i.e.However, according to the docs, this shouldn't be required when using Vite.
System Info
The text was updated successfully, but these errors were encountered: