DEV Community

Discussion on: How to migrate your library from Vue2 to Vue3

Collapse
 
rchl profile image
Rafał Chłodnicki
  • In the useApi.js code block you are not showing where the inject function comes from. Maybe worth adding?
  • It looks like the convention for "native" Vue libraries is to use a separate (next) branch to add support for Vue3. Is there anything blocking one from adding support on the existing branch as a new feature?
Collapse
 
alvarosabu profile image
Alvaro Saburido

Good catch, I will add it, it's important to be added

For the second one yes is good to use "next" branch is also referencing to npm channel next where you can install from a certain tag version . Lets see it with the following practical example

Your library for vue2 is currently on version 1.2.0, you create a branch called next, that is going to be some kind of a "master/develop" branch for the new version, and you start there from 2.0.0, you would do the same git flow as you normally do, create a feature branch, or bugfix from next and merged into next.

That way in the same repo you mantain a 1.x.x version for vue2 and a 2.x.x of the library for vue3. When you feel the next version is ready you can merge it into master so its your stable version of the package.

I would suggest to wait a little to do that, in the meantime suggest your user to install the vue3 compatibility version trough 'npm i your-awesome-lib@next'

I hope it helps, if you have more question feel free to write me, and thanks for the feedback

Collapse
 
peoray profile image
Emmanuel Raymond

Thanks for the article:)

I have some follow-up questions:

  • Does that mean all you have to do to migrate an existing library is to do as the article suggest? Is there something else to do when migrating (I'm assuming you have to update some dependencies like Vue from 2.x.x to 3.x.x)?

  • Can I also use the next version the same way as the main version? Say I install the @next version but don't want to use it with composition API, will this work?

Thread Thread
 
alvarosabu profile image
Alvaro Saburido

Hello Emmanuel, thanks for reaching out

  1. Yes, you have to update vue to 3.x version, and all related dependencies. This article covers adapting the installation of the plugin to the new standard in vue 3.
  2. Composition API is purely additive, so the library would work exactly the same if use with the Options API. It does depends if they're more breaking changes other than the installation added by the authors. In that case they should be reflected in a proper "Migration Guide" in the documentation.

I hope this clarifies your doubts. If you have any other, feel free to ask.

Happy coding.

Thread Thread
 
peoray profile image
Emmanuel Raymond • Edited

Thanks for your reply. This reason I ask is that I'm planning on making a package and from what I have read, I can just go ahead and use the new standard and it will work for both Vue 2 and Vue 3, yeah?. This is what I need clarification on.

Since Vue.component isn't available for plugin in Vue 3, if I use app.component as you showed in the article and someone using Vue 2.x.x installs my package and then call it with Vue.use(packageName) in their main.js, will this process work?