diff --git a/README.md b/README.md index 2890880..762b19b 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Or locally in any component ```js import { VuePaycard } from 'vue-paycard' +// In v0.5+ you don't need the brackets above export default { components: { diff --git a/vue-paycard.js b/vue-paycard.js index d3411af..2fb11ca 100644 --- a/vue-paycard.js +++ b/vue-paycard.js @@ -1,13 +1,39 @@ -import VuePaycard from './src/components/VuePaycard' +// Import vue component +import VuePaycard from './src/components/VuePaycard.vue' -const VuePaycardPlugin = { - install (Vue) { - Vue.component('VuePaycard', VuePaycard) - } +// install function executed by Vue.use() +const install = function (Vue) { + if (install.installed) return + install.installed = true + Vue.component('VuePaycard', VuePaycard) } -// Export as a plugin -export default VuePaycardPlugin +// Create module definition for Vue.use() +const plugin = { + install +} + +// To auto-install when vue is found +// eslint-disable-next-line no-redeclare +/* global window, global */ +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() +VuePaycard.install = install + +// Export component by default +export default VuePaycard -// Export as individual components +// Export single (backwards compatibility) export { VuePaycard }