Skip to content

Commit

Permalink
Re-factor wrapper script to expose both as plugin
Browse files Browse the repository at this point in the history
and SFC
  • Loading branch information
svale committed Jan 27, 2020
1 parent c4e9f57 commit a82830d
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@
* Adapted by (c) 2018 Svale Fossåskaret (http://kartoteket.as/team/svale.html / @Fossesvale)
* @license MIT.
*/
import ImageUploader from './ImageUploader.vue'
// Import vue component
import component from './ImageUploader.vue'

const ImageUploaderPlugin = {
install(Vue) {
Vue.component('image-uploader', ImageUploader)
},
// Declare install function executed by Vue.use()
export function install(Vue) {
if (install.installed) return
install.installed = true
Vue.component('ImageUploader', component)
}

// Install by default if using the script tag
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(ImageUploaderPlugin)
// Create module definition for Vue.use()
const plugin = {
install,
}

export default ImageUploaderPlugin
export { ImageUploader }
// Auto-install when vue is found (eg. in browser via <script> tag)
let GlobalVue = null
if (typeof window !== 'undefined') {
GlobalVue = window.Vue
} else if (typeof global !== 'undefined') {
GlobalVue = global.Vue
}
if (GlobalVue) {
GlobalVue.use(plugin)
}

// Inject install function into component - allows component
// to be registered via Vue.use() as well as Vue.component()
component.install = install

// To allow use as module (npm/webpack/etc.) export component
export default component

0 comments on commit a82830d

Please sign in to comment.