question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for web-components

See original GitHub issue

Hello @antfu,

unfortunately I can not use vue-demi in a micro frontend setup, where the container SPA provides the vue instance via window.Vue. The web components are using vue-demi but they crash since it tries to install the composition api on a non existing Vue instance.

[vue-composition-api] No vue dependency found. (in getRegisteredVueOrDefault)

is there any workaround to make this default install(Vue) call optional?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lstoeferlecommented, Mar 10, 2021

Unfortunately my time is currently very limited, so I decided to add the solution here instead of creating an example project.

Things that have to be done in the container-ui project (the host Vue SPA for the web components):

// main.js
import Vue from 'vue';
import * as VueDemi from 'vue-demi';

// Make Vue and VueDemi global, so the web components can use it
window.Vue = Vue;
window.VueDemi = VueDemi;

Things that have to be done in the web-component project:

First move vue, @vue/composition-api and vue-demi to the devDependencies.

// vue.config.ts

module.exports = {
  chainWebpack: (config) => {
    if(process.env.NODE_ENV === 'production')
      // Exclude following dependencies from production build, keep for local serving
      config.externals({
        vue: 'Vue', // this should be externalized by default if the vue-cli build target is set to 'wc'
        'vue-demi': 'VueDemi'
      })
  } 
}

Also make sure all composition api related imports are imported from vue-demi in both projects.

This should prevent having multiple instances of the composition api in a micro-frontend setup with web-components

1reaction
lstoeferlecommented, Mar 4, 2021

Found and fixed the issue. I will create an example project on GitHub the next days and share the link here 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

"web components" | Can I use... Support tables for ... - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >
Web Components - MDN Web Docs - Mozilla
Web Components is a suite of different technologies allowing you to create ... Add child elements, event listeners, etc., to the shadow DOM ......
Read more >
webcomponents.org
Browser support · Chrome · Opera · Safari · Firefox · Edge ...
Read more >
Custom Elements Everywhere
Custom Elements are the lynchpin in the Web Components specifications. They give developers the ability to ... feat: Add native support for custom...
Read more >
A Complete Introduction to Web Components in 2022 - Kinsta
Web Components are a standard way to create reusable and modular HTML elements without using a JavaScript framework.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found