-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathwrapper.ts
41 lines (34 loc) · 854 Bytes
/
wrapper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Import vue component
import Vue from 'vue'
import Mapbox from './Mapbox.vue'
import { VueConstructor } from 'vue'
declare global {
interface Window {
Vue?: VueConstructor<Vue>
}
interface InstallFunc {
(Vue: VueConstructor): void
installed?: boolean
}
}
// Declare install function executed by Vue.use()
let install: InstallFunc
install = function(Vue: VueConstructor): void {
if (install.installed) return
install.installed = true
Vue.component('Mapbox', Mapbox)
}
// Create module definition for Vue.use()
const plugin = {
install,
}
// Auto-install when vue is found (eg. in browser via <script> tag)
let GlobalVue = null
if (typeof window !== 'undefined') {
GlobalVue = window.Vue
}
if (GlobalVue) {
GlobalVue.use(plugin)
}
// To allow use as module (npm/webpack/etc.) export component
export default Mapbox