Skip to content

Commit

Permalink
feat: auto install when using CDN (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 24, 2020
1 parent 1c64108 commit 77ba15b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/index.ts
@@ -1,6 +1,5 @@
import Vue, { VueConstructor } from 'vue'
import { Data, SetupFunction, SetupContext } from './component'
import { currentVue } from './runtimeContext'
import { install } from './install'
import { mixin } from './setup'

Expand All @@ -10,17 +9,12 @@ declare module 'vue/types/options' {
}
}

const _install = (Vue: VueConstructor) => install(Vue, mixin)
const plugin = {
install: _install,
}
// Auto install if it is not done yet and `window` has `Vue`.
// To allow users to avoid auto-installation in some cases,
if (currentVue && typeof window !== 'undefined' && window.Vue) {
_install(window.Vue)
const VueCompositionAPI = {
install: (Vue: VueConstructor) => install(Vue, mixin),
}

export default plugin
export default VueCompositionAPI

export { nextTick } from './nextTick'
export { default as createElement } from './createElement'
export { SetupContext }
Expand All @@ -40,3 +34,8 @@ export * from './apis/lifecycle'
export * from './apis/watch'
export * from './apis/computed'
export * from './apis/inject'

// auto install when using CDN
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(VueCompositionAPI)
}

0 comments on commit 77ba15b

Please sign in to comment.