vitejs / vite-plugin-vue2

Vite plugin for Vue 2.7
MIT License
550 stars 46 forks source link

Multiple vue versions imported #46

Open samturrell opened 2 years ago

samturrell commented 2 years ago

Hi, i'm trying to use this plugin for a vue 2 app via vite, but it appears to be pulling in two versions of vue:

image

it also throws the following errors in the console when the input is updated, which i assume is related

image

This issue can be reproduced in this example by running yarn dev

https://github.com/samturrell/vite-issue

Hopefully somebody can help? I'm at a bit of a loss here.

I'm having to pull in import Vue from 'vue/dist/vue.js'; rather than just vue otherwise it errors with

vue.runtime.esm.js:4568 [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

I feel like this might also be related, but i'm not sure what else i need to do.

emosheeep commented 2 years ago

I just started the project and found the error. If you want to change the default import-source of vue, use resolve.alias instead.

export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      vue: 'vue/dist/vue.js'
    }
  }
})

Directly import from vue/dist/vue.js will split the relations among the dependencies, which result in multi instance exception.