
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
@telia/vue-web-component-wrapper-ie11
Advanced tools
wrap a vue component as a web component, for IE 11 too.
Wrap and register a Vue component as a custom element (with Shadow DOM), in IE 11 and beyond.
this.$emit()
callsimport '@webcomponents/webcomponentsjs'
import Vue from 'vue'
import wrap from '@telia/vue-web-component-wrapper-ie11'
import VueComponent from './VueComponent.vue'
const CustomElement = wrap(Vue, VueComponent, {
// globalStyles: true,
// jsonMapping: true,
})
window.customElements.define('vue-component', CustomElement)
Now you can just add <vue-component>
anywhere in the page, and the component will appear fully loaded, like it was made by the browser itself. This seamless step is arguably the best part of utilizing Web Components.
It works with async components as well - you can pass an async component factory function that returns a Promise, and the function will only be called when an instance of the custom element is created on the page:
const CustomElement = wrap(Vue, () => import(`VueComponent.vue`))
window.customElements.define('my-element', CustomElement)
You can also import or just have a <script>
tag point to @telia/vue-web-component-wrapper-ie11/dist/vue-wc-wrapper.global.js
, which will expose wrap
as wrapVueWebComponent
globally on the window object.
--target wc
to --target lib
(or anything else really) in the Vue-CLI run options (probably in package.json)
--inline-vue
if you want to make sure Vue is included in your web component.wrap()
method as shown aboveNote that with the above approach, you'll be putting all web components in a single bundle. This section does not document how to make a bundle per web component.
Easiest is to do:
import '@webcomponents/webcomponentsjs'
The polyfill bundle with check if the browser supports web components and will apply polyfills as needed. If you want to reduce bundle size even further, that is possible, just consult the @webcomponents/webcomponentsjs documentation on using their loader.
Whatever you do, do not import the custom elements and other polyfills directly, as it will overwrite native browser functionality for browsers like Chrome, that already support Web Components.
The styles will leak through to your web components in IE 11 in several cases, like when passing slots to the web component. Make sure you use a way to encapsulate your styles like BEM, Scoped styles (has drawbacks of its own), or CSS Modules. Choose the one that fits you.
Returns a Custom Element, that can be used in the browser-provided window.customElements.define
call.
Type: object
Your Vue instance.
Type: object
Your source component (can also just be a simple javascript object {}
, not a separate vue file).
Type: object
Type: boolean
Default: true
Setting this to false will skip a 0ms setTimeout() call, but will also break Vue's scoped attribute support in the form of FOUC's.
Type: boolean | object
Default: false
If you want auto-injection of the global styles, set it to true
.
You can specify more granular rules for global style injection, refer to this part of the source code for details. The defaults should be reasonable for most developers.
Type: boolean
Default: false
If you want automatic deserialization of javascript objects and arrays.
Then just pass "my-array-json" like :my-array-json="JSON.stringify({ a: 1 })"
to your web component, it will parse it to the prop called "myArray" in the vue file as a regular js object again. If the json is invalid it will become "INVALID_JSON". This works for props defined with type Array
and Object
All props
declared in the Vue component are exposed on the custom element as its properties. Kebab-case props are converted to camelCase properties, similar to how they are converted in Vue.
Setting properties on the custom element updates the props passed to the inner Vue component.
Setting attributes on the custom element updates corresponding declared props. Attributes are mapped to kebab-case. For example, a prop named someProp
will have a corresponding attribute named some-prop
.
Attributes that map to props declared with type: Boolean
are auto-casted into boolean values in the following rules:
""
or same value as attribute name: -> true
"true"
-> true
"false"
-> false
Attributes that map to props declared with type: Number
are auto-casted into numbers if the value is a parsable number.
Custom events emitted on the inner Vue component are dispatched on the custom element as a CustomEvent
. Additional arguments passed to $emit
will be exposed as an Array as event.detail
.
Slots work the same way as expected, including named slots. They also update when changed (using MutationObserver
).
Scoped slots however, are not supported as they are a Vue specific concept.
When the custom element is removed from the document, the Vue component behaves just as if it's inside a <keep-alive>
and its deactivated
hook will be called. When it's inserted again, the activated
hook will be called.
If you wish to destroy the inner component, you'd have to do that explicitly:
myElement.vueComponent.$destroy()
Special thanks to the prior work by @karol-f in vue-custom-element.
MIT
FAQs
wrap a vue component as a web component, for IE 11 too.
The npm package @telia/vue-web-component-wrapper-ie11 receives a total of 41 weekly downloads. As such, @telia/vue-web-component-wrapper-ie11 popularity was classified as not popular.
We found that @telia/vue-web-component-wrapper-ie11 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.