Skip to content

Export components individually #32

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

Closed
walfly opened this issue Jan 22, 2022 · 4 comments
Closed

Export components individually #32

walfly opened this issue Jan 22, 2022 · 4 comments

Comments

@walfly
Copy link
Contributor

walfly commented Jan 22, 2022

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
Copy link

RWave88 commented Mar 3, 2022

@walfly is there any way to import it locally?

@jarvisniu
Copy link
Owner

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: rollup/rollup#1961 (comment)

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
Copy link
Owner

Published at v0.3.10

@walfly
Copy link
Contributor Author

walfly commented Mar 11, 2022

Sounds great, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants