Publish your Nuxt SPA as a vue-custom-element
nuxt-custom-element is a Nuxt.js module that uses vue-custom-element to publish your Nuxt SPA as a custom element / web-component.
See the example folder for an example project.
To run the example locally, clone this repo, run yarn install or npm i and then yarn example or npm run example
Install the module package
$ yarn add nuxt-custom-element
$ npm i nuxt-custom-element
Next add the nuxt-custom-element module to your config:
// nuxt.config.js
mode: 'spa', // this module only works in SPA mode!
modules: [
['nuxt-custom-element', { name: 'my-nuxt-spa' }]
]
name requiredstring (default: customElement) normally in dev mode, dont
The global name of your custom element. This should be a valid javascript identifier as its used as the globalName of your custom element
Make sure to choose a unique name, if two Nuxt app’s have the same globalName that will result in errors
elementNamestring (default: same as name)
Optional, the name of your custom element. If you want your custom element to have a different name then the Nuxt globalName property
// module options
{ name: 'nce', elementName: 'nuxt-custom-element' }
// results in
window.$nce
<nuxt-custom-element></nuxt-custom-element>
propsarray (default: [])
Optional, the props that your custom element supports.
// module options
{ props: ['path'] }
<custom-element path="/about"></custom-element>
// pages/index.vue
mounted() {
console.log('Path prop has value', this.$root.path)
}
Just run nuxt dev, this module adds a static index.html which already has your custom component listed
Run nuxt build in your project and check the ./dist folder. The dist folder should contain 3 files, a js file, a css file and an index.html
Currently the minimum bundle size seems to be ~180KB. This includes the basic Nuxt.js app and all polyfills to run your custom element in IE9+
The minimum bundle size was reached by disabling most Nuxt.js features
_uid: 0, but when using nuxt-custom-element it has _uid: 1head. Using head will probably effect the parent page as well, not just your custom elementWe use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.