Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto install when using CDN #403

Merged
merged 2 commits into from Jun 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}