vuejs / vue-loader

📦 Webpack loader for Vue.js components
MIT License
4.99k stars 915 forks source link

How to compile vue2 file and vue3 file #1817

Closed BlackCubeNo99 closed 3 years ago

BlackCubeNo99 commented 3 years ago

Version

16.1.2

Reproduction link

Steps to reproduce

I installed vue-loadervue-template-compiler@vue/compiler-sfcvue2vue3

// package.json
"devDependencies": {
  "vue-loader": "16.1.2",
  "vue-template-compiler": "2.6.12",
  "@vue/compiler-sfc": "3.0.7"
},
"dependencies": {
  "vue": "2.6.12",
  "vue3": "npm:vue@3.0.7"
}

How to set vue2 and vue3 config ?

// webpack.config.js
module.exports = {
  entry: ['a.js', 'b.ts'],
  resolve: {
    alias: {}
  }
}

a.js use vue2

// a.js
import Vue from 'vue'
import App from './App.vue'

new Vue({
  el: '#app',
  render: h => h(App)
})

b.ts use vue3

// b.ts
import { createApp } from 'vue3'
import App from './App.vue'

createApp(App).mount('#app')

What is expected?

compile Vue2 and Vue3 at the same time

What is actually happening?

Cannot compile Vue2 and Vue3 at the same time

privatenumber commented 3 years ago

AFAIK this isn't possible and something I'd like as well, especially for a smooth migration path.

I made vue-2-3 to make migration easy, but this is one of the remaining problems that make it hard to do it in one build.