-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Make vue available to other libraries without having to import it #8278
Comments
You may want to use https://github.com/ktsn/babel-plugin-remove-vue-extend |
👌 How does that handle stuff like mixins (usage) or directly calling methods? EDIT: Didn't rtfm, this looks perfect. I'll have to try it out to see how well it actually works though. I might have to massage the types a bit to get #2 working. |
@ktsn can we close this or is there anything we could do in Vue core to improve the situation? |
I'm fine with having to use |
Alternatively we may try to detect duplicate Vue imports. |
Yeah that would be helpful, the current errors don't really indicate what's actually going on very well. Is our current setup likely to be a problem with vue-test-utils and |
A few months ago I have asked for help with an issue related to this one on stackoverflow. |
The solution should also allow to use .vue files in packages, which, with the original proposal at the top of this thread would probably not be possible. |
After giving a hard look at the problem, the only solution that I found at the moment (with webpack) is to add vue as an external import wherever you import it.
and then import vue.js with a script tag (or an equivalent solution) in your html file. That means that you have to pack them as standalone libraries, with, in webpack.config.js
and in tsconfig.json
As a side effect with this solution you can also work with vue files in your libraries. The proposed solution at the top of this issue would in any case not allow that, because you cannot inject the vue constructor in a vue file (as far as I understand). |
I use this to make sure the same file is always loaded, you can omit the resolve: {
alias: {
'vue$': path.resolve(__dirname, '../node_modules/vue/dist/vue.runtime.esm.js')
// 'vue$': 'vue/dist/vue.runtime.esm.js'
}
} |
I had the "duplicate import" problem in a monorepo project using Lerna, and it seems to be related to the same problem when using From what I've found, the common generalized solution seems to be to mark your dependency as an 'external' in whatever build configuration you're using. I'm using Electron with module.exports = {
pluginOptions: {
electronBuilder: {
// List native deps here if they don't work
externals: ['my-shared-components'],
}
}
} |
Title needs work, idk what to call this.
What problem does this feature solve?
Writing a component library with typescript requires importing Vue so you can use
Vue.extend(...)
to get typings. This causes problems when webpack decides to load a different instance of vue.See vuetifyjs/vuetify#4068
What does the proposed API look like?
Local registration to accept a function that synchronously returns a component, calling it with the parent vue instance.
The library can then do:
And be used like:
Of course that would then cause other problems, particularly where we use methods directly from other components. Maybe something that adds types like
Vue.extend()
but doesn't have any runtime behaviour would be better instead?The text was updated successfully, but these errors were encountered: