-
Notifications
You must be signed in to change notification settings - Fork 102
Add support for Vue 3 with web-component-wrapper #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I started working on the port of the wrapping library, but we also need to add back some capabilities to the Vue-3-compatible versions of vue-loader (& rollup-plugin-vue) in order to be able to inject styles into shadowRoot. So this is being worked on, but it will still be some time before it's ready. |
Hi, any news on this? Would be really great to have this abillity |
This will still take a while, mostly because we still need to add shaoowRoot CSS injection back into the build tooling. Without that, this lib is pretty useless. |
when we can expect vue 3 support? do you have any specific idea? days? weeks? months? |
weeks to months. The work I described will take some time and has a bit lower priority at this moment while we get core more stable etc. |
I have published a Vue3 compatible version of this package @ https://www.npmjs.com/package/vue3-webcomponent-wrapper. It supports reactive attributes, events & slots. Feel free to use it if you are not keen on shadow-root. If you have found an issue with the wrapper, please submit a PR on https://github.com/cloudera/hue/tree/master/desktop/core/src/desktop/js/vue/wrapper |
How can I use router or store on a Vue web component if those should be declared on the main.js file? |
i try the demo and it looks like you dont have a shadow root any plans on that ? @sreenaths |
@DrMabuse23 Sorry that I don't have immediate plans for shadow root . |
@nunofhfontes Was that question regarding vue3-webcomponent-wrapper? |
You can use it like this:
|
how can i publish a component and use it in another project ? not whole app, just one component. thanks |
@BlahaMarek For instance following is how we package a er-diagram component.
Note: |
Guys, maybe move this discussion about |
@LinusBorg: Do you have any update for us on the Vue 3 support? |
@TFohrer I would recommend you to start with Vue2 and @vue/composition-api and put Vue3 on hold for now. It's working, it's great and all that, but it's not ready for production use. Besides the web component wrapper, Test-utils and DevTools still have work to be done. There is a fork for the wrapper that works with Vue3, but @vue/composition-api is really good and would serve as an in between steps toward Vue3. You can even utilize @vue/component-api as an alternative to Vuex (IMHO you do not need vuex with vue3, as long as the Vuex DevTools are not critical to you). When Vue3 is production ready, all you need to do is to replace "@vue/composition-api" with "vue" in your imports and you are good to go. |
@LinusBorg I want you to check it if you have time 🙏 |
@TatsuyaYamamoto I tried your repository and got this for v3 (vue3-webcomponent-wrapper works for me but no shadowDom, no styles):
|
Vue 3 will have built-in support for web component wrappers in 3.2. you can already test it in the current beta. |
Documentation will come with the stable release. Guessing what you did wrong: So You don't replace import MyComponent from './MyComponent.vue'
const myWebComponent = defineCustomElement(MyComponent)
customElements.define('my-web-component', myWebComponent) |
Thanks a lot! I also found a tweet about it. In this func styles is undefined in component:
|
That needs some special treatment in the build tooling (vue-loader etc), which will come with the 3.2 release. |
@LinusBorg I know the docs are still kind of "TBD"; however, is it possible to bundle a small Vue 3 app as its own custom component with |
@adamdehaven please see https://v3.vuejs.org/guide/web-components.html#definecustomelement and |
@adamdehaven I don't think that's possible, and I would be interested in asking why you would want to wrap a whole SPA in a custom element. that's not really the normal use case for custom elements. |
@LinusBorg And that's good approach. Hovewer, with vue-custom-element I do allow it. There are cases like e.g. chat app that you handle to client and he/she just inset HTML tag into page (e.g. |
@LinusBorg similar to the chat example mentioned above, I have a passwordless auth app that would be ideal to embed as a custom element (especially for use within other frameworks). The app has internal routing via Vue Router to handle the webauthn flow and utilizes Vuex. @karol-f is vue-custom-element compatible with Vue 3? |
@adamdehaven it's not. I had plans to do it but as Vue 3 support Custom Elements out of the box I don't think it's necessary. |
I see how that's nice for the client, but at the same time, the difference between that and instead having to call one function and pass it a selector to mount a Vue app is rather small, don' you think? <div id="chat-app"></div>
<script>
ChatApp.start('#chat-app')
</script> And if you really need the approachability of the custom element, why not use a simple custom element to mount an actual Vue app inside of it? const MyChatApp extends HTMLElement {
connectedCallback() {
const app = createApp(App)
app.mount(this)
}
}
customElements.register('my-chat-app', MyChatApp) Does it really need shadow DOM? does it need to have props and events? All that being said, You likely can use Vuex and the router (with memoryHistory) in a custom element (though I haven't tried out), but not through the usual |
@LinusBorg I understand your point of view. However there are some things to consider:
But anyway I agree with Your choice. Vue-custom-element had different assumptions so it works such way. This approach is not better or worse. |
Good points. As ai said there are probably workarounds to make it work. The focus of |
Vue 3.2 is here but I still get |
@leonheess there is built in solution already - https://blog.vuejs.org/posts/vue-3.2.html |
@karol-f That doesn't enable me to build as a web component for others to use, does it? |
You can https://v3.vuejs.org/guide/web-components.html#tips-for-a-vue-custom-elements-library |
If this helps anyone, I managed to build a web component following documentation for Vue3 custom elements and SFC, using --target lib, see https://v3.vuejs.org/guide/web-components.html#sfc-as-custom-element
Vue-cli documentation is not clear enough about the current status of build with --target wc with Vue3. Is there a vue-cli update scheduled for compatibility with build --target wc and Vue3 ? |
Not sure how that link helps. In Vue 2 I can do |
|
@karol-f That's not the same. It drops all scoped styles outside of the main/App file for example. |
@leonheess I made a PR to use custom elements without shadow dom (which skip global styles). Here's how to use it in your project until it's merged : vuejs/core#4314 (comment) |
A little late to the discussion, but we have currently the problem with vue3, that we want to move to a microfrontend structure and want to wrap our microfrontend-vue3-apps as web components. A real world example: A customer microfrontend displaying a list of customers and a details page for a single customer where we need a subrouting ("/customers/", "/customer/:id") and maybe want to store the current customer in a pinia store. The workaround above is probably a way to solve this, but I would recommend that there is an official way to solve this issue (or at least a section in the documentation about it). Especially regarding competitiveness with other reactive frameworks where this is not a problem at all and officially supported. |
Hi Ho, |
@EranGrin Thank you very much for this plugin ! We are in the middle of a Vue2 -> Vue3 migration and need to embed some of our vue3 packages as web components into our vue2 client. So far so good, CSS and deep css is well injected, and we were able to inject i18n + pinia as well as our own components as plugins ! |
I'm trying to use slots in the components but it doesn't seem to be working: Slot code inside the component:
How it is called:
When I open the page where the custom element is called, only the default text 'No content passed!!' appears |
@busella73 Please refer to the docs. This ticket ain't the place to ask this. Use: |
Maybe i don't explain myself correctly. I use: "vue": "^3.3.4", This is the component that i build as web component:
this is the script i use to build it:
and this is the command i use to run the script:
If i use the element is rendered as a document fragment and is not visible on the page, if i use the element is rendered at the end of the page and not used as slot. I think this is an issue.
|
Any update on this? I want the user to be able to change the styling of my custom element with their CSS, but with shadow DOM it doesn't seem to be possible? |
@onurusluca you can use CSS var on the :root and then use them inside the shadow DOM
Inside the web component
|
i met the same obstacle and came up with a workaround |
I wanted to migrate my Vue 2 project to Vue 3.
The problem is, that the
wrap
-function is still using and expecting theVue
-instance, which is why i get the following error:The
main.js
:This makes total sense, since global Vue doesn't exist anymore.
Any work around on this?
The text was updated successfully, but these errors were encountered: