-
Notifications
You must be signed in to change notification settings - Fork 157
feat(vue 3): migrate from Vue.default.version to a fallback #847
Conversation
In Vue 3 `version` is an explicit export, while in Vue 2 it's a property of the default export. This way _does_ give a warning⚠️ when using Vue 2: `"export 'version' (imported as 'A') was not found in 'vue'`. I'm not too sure how to avoid that
When this file is transpiled, it becomes import Vue__default, { version } from 'vue'; In Vue 3, there is no default export. So we get errors like this:
Not sure how to fix it yet. |
I think it would be great to use vue-demi which provide compatibility layers between Vue 2 and 3 for plugins, something like this: import { isVue2, isVue3 } from 'vue-demi'
// ...
searchClient.addAlgoliaAgent(
`Vue (${isVue2() ? 2 : 3 })`
); |
That could be interesting, but the real version we are looking for there is |
Yeah, I suppose you can do something like this which seems to work for Vue 2 and Vue 3: searchClient.addAlgoliaAgent(
`Vue (${require('vue').version})`
); |
function getVueVersion() {
if (typeof window !== 'undefined' && typeof window.Vue !== 'undefined') {
return window.Vue.version; // for umd
} else {
return require('vue').version;
}
} What do you think? |
That's even better! 😄 |
are you sure mixing require/import will not cause issues in other platforms / bundlers? |
nope, not at all 😅 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 74272f3:
|
Apparently, in one of my sandboxes, I'm seeing an issue with (probably) this |
3341e04
to
3c41c80
Compare
3c41c80
to
74272f3
Compare
…vue-instantsearch#847) Co-authored-by: eunjae-lee <[email protected]>
In Vue 3
version
is an explicit export, while in Vue 2 it's a property of the default export.This way does give a warning⚠️ when using Vue 2:
"export 'version' (imported as 'A') was not found in 'vue'
. I'm not too sure how to avoid thatsee: https://v3.vuejs.org/guide/migration/global-api-treeshaking.html