instantsearch icon indicating copy to clipboard operation
instantsearch copied to clipboard

Tree Shaking with Vite not working

Open jenjen75 opened this issue 3 years ago • 2 comments

Bug 🐞

What is the current behavior?

To reduce bundle-size, I follow the documentation recommandation : https://www.algolia.com/doc/guides/building-search-ui/going-further/improve-performance/vue/?client=Vue+3#optimize-build-size

When running npm run build, all vue-instantsearch is compiled whereas I simply do import 'vue-instantsearch/vue3/es'; in counter.js file.

Make a sandbox with the current behavior

https://stackblitz.com/edit/vitejs-vite-nyimj5?file=counter.js&terminal=dev

What is the expected behavior?

import 'vue-instantsearch/vue3/es'; in counter.js file should import nothing

What is the proposed solution?

What is your recommandation to make tree-shaking working ?

What is the version you are using?

"vue-instantsearch": "^4.6.0"

jenjen75 avatar Oct 16 '22 20:10 jenjen75

I hope this can be fixed in Vite, as it's fixed in webpack, but for the mean time, you can import the individual components like this:

import SearchBox from 'vue-instantsearch/vue3/es/src/components/SearchBox.vue'

Haroenv avatar Oct 18 '22 11:10 Haroenv

I am facing the same issue and tried several ways to import the components (directly in the template, global plugin with app.use(), with InstantSearch as a module or as a component, InstantSearchSsr etc.) and none worked as vite failed to import InstantSearch :

[vite-plugin-pwa:build] [vite]: Rollup failed to resolve import "vue-instantsearch/vue3/es/src/components/InstantSearch.vue" from "src/modules/instantsearch-ui.ts"

alex-galey avatar Oct 20 '22 16:10 alex-galey