jarvisniu / vue-zoomer

Zoom the image or other thing with mouse or touch
MIT License
150 stars 38 forks source link

Export components individually #32

Closed walfly closed 2 years ago

walfly commented 2 years ago

This plugin only registers 2 components, it doesn't provide any other additional features. It would be better to import these components where they are used instead of registering them globally using the vue.use syntax.

RWave88 commented 2 years ago

@walfly is there any way to import it locally?

jarvisniu commented 2 years ago

Thank you, this is totally acceptable.

But when I build it, I found that the mixed export (default and named) has a big problem. The rollup says:

(!) Mixing named and default exports
https://rollupjs.org/guide/en/#output-exports
The following entry modules are using named and default exports together:
src/index.js
src/index.js

Consumers of your bundle will have to use chunk['default']
to access their default export, which may not be what you want.
Use `output.exports: 'named'` to disable this warning

And here has an explaining: https://github.com/rollup/rollup/issues/1961#issuecomment-423037881

So I changed it to this:

import VueZoomer from './vue-zoomer.vue'
import VueZoomerGallery from './vue-zoomer-gallery.vue'

export default {
  install (Vue) {
    Vue.component('VZoomer', VueZoomer)
    Vue.component('VZoomerGallery', VueZoomerGallery)
  },
  // for locally register
  Zoomer: VueZoomer,
  Gallery: VueZoomerGallery,
}

And use as:

<!-- page1.vue -->
<script>
import VueZoomer from 'vue-zoomer'

export default {
  components: {
    VZoomer: VueZoomer.Zoomer,
    VZoomerGallery: VueZoomer.Gallery,
  },
}
</script>

A little ugly, but without problem.

Maybe a better way is:

// lib.js
export { plugin, VueZoomer, VueZoomerGallery }
// globally usage
import { plugin } from 'vue-zoomer'
Vue.use(plugin)
// locally usage
import { VueZoomer, VueZoomerGallery } from 'vue-zoomer'

But this is not backwards compatible.

jarvisniu commented 2 years ago

Published at v0.3.10

walfly commented 2 years ago

Sounds great, Thanks!