Anna Monus | Technical Writer & Editor

Should you use Vue.js within an existing framework?

Pros and cons of adding Vue.js to your app as a second framework

Vue.js has been rapidly gaining traction in recent years. Developers love it for its flexible design, impressive ecosystem, and friendly learning curve. Vue.js is not only a popular choice for creating a new application but you can also include it within an existing framework. While this decision certainly has its pros, it comes with some challenges as well.

Why use Vue.js within another framework?

Vue.js has a couple of features that make it attractive compared to other front-end frameworks. Its component-based modular architecture makes it easy to integrate it into an existing user interface. It also has a quite active open-source community that creates loads of components, UI libraries, and plugins ready to use.

Developers praise Vue.js for its reactive data binding mechanism and efficient state management, too. Vue.js automatically refreshes components whenever it's necessary, which leads to highly performant UIs. It also uses one-way data flow and rendering which makes it easier to predict the app's behavior. This can be a huge plus when you are dealing with a complex project.

Why not use Vue.js within another framework?

Ending up with an inconsistent architecture is probably the biggest risk of using Vue.js within an existing framework. You can add a few Vue.js components to your app either manually or with a tool like ngVue without many problems. However, after a while, your app's complexity will be rapidly growing. Maintenance and debugging will become a chore and errors will sooner or later appear.

Alternatively, you can pick a meta-framework such as single-spa that provides a better architecture. Meta-frameworks allow you to create micro-frontends similar to backend microservices. For a new app, this can be an excellent solution but migrating an existing app to a meta-framework poses several additional risks.

You can also create two separate apps running within their own iframes and communicating through postMessage APIs. Spotify's desktop app, for instance, uses a similar approach. Still, finding a coherent architecture that scales without issues is not an easy task.

Greater complexity can lead to issues with Webpack and other module bundlers as well. Just think about larger bundle sizes and duplicate config files. Cross-origin communication between window objects can also cause performance issues. Besides, it will take more time to test your app, as there might be unexpected interactions between the two frameworks.

The verdict

Whether it's worth adding Vue.js to your existing framework highly depends on your stack. It can be a good idea to make a cost-benefit analysis and evaluate all the potential risks. Cutting-edge Vue.js features might improve your app's user experience for sure but you have to prepare for increasing complexity and potential inconsistencies as well.