-
-
Notifications
You must be signed in to change notification settings - Fork 199
Added Vue3 support #746
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
Added Vue3 support #746
Changes from all commits
8d07790
e376be2
e702197
6f83868
c9f83bc
85d42cd
c344809
08509da
63cfd1a
bc182bd
7d2917e
d7903e4
d49352b
35e508f
43f66c9
24f7652
33d2ac5
449a0af
e51165d
06782ae
5abb25d
40f8ae8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createApp } from 'vue'; | ||
import App from './App' | ||
|
||
createApp(App).mount('#app'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vue2 code is pretty much compat with vue3, except for how you originally render the app. So I have v2 and v3 entry files. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createApp } from 'vue'; | ||
import App from './App' | ||
|
||
createApp(App).mount('#app'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<div id="app"> | ||
<img src="./assets/logo.png"> | ||
<hello></hello> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Hello from './components/Hello.vue' | ||
|
||
class TestClassSyntax { | ||
|
||
} | ||
|
||
export default { | ||
name: 'app', | ||
components: { | ||
Hello | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
#app { | ||
font-family: 'Avenir', Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
</style> | ||
|
||
<style lang="scss"> | ||
#app { | ||
display: flex; | ||
color: #2c3e90; | ||
} | ||
</style> | ||
|
||
<style lang="less"> | ||
#app { | ||
margin-top: 40px; | ||
} | ||
</style> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typescript in vue2 vs vue3 is different enough that I have 2 separate directories. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<template> | ||
<div class="hello"> | ||
<h1>{{ msg }}</h1> | ||
<h2>Essential Links</h2> | ||
<ul> | ||
<li><a href="https://vuejs.org" target="_blank">Core Docs</a></li> | ||
<li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li> | ||
<li><a href="https://gitter.im/vuejs/vue" target="_blank">Gitter Chat</a></li> | ||
<li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li> | ||
<br> | ||
<li><a href="https://vuejs-templates.github.io/webpack/" target="_blank">Docs for This Template</a></li> | ||
</ul> | ||
<h2>Ecosystem</h2> | ||
<ul> | ||
<li><a href="https://router.vuejs.org/" target="_blank">vue-router</a></li> | ||
<li><a href="https://vuex.vuejs.org/" target="_blank">vuex</a></li> | ||
<li><a href="https://vue-loader.vuejs.org/" target="_blank">vue-loader</a></li> | ||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank">awesome-vue</a></li> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default { | ||
name: 'hello', | ||
data () { | ||
return { | ||
msg: 'Welcome to Your Vue.js App' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
<style scoped> | ||
h1, h2 { | ||
font-weight: normal; | ||
} | ||
|
||
ul { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
|
||
li { | ||
display: inline-block; | ||
margin: 0 10px; | ||
} | ||
|
||
a { | ||
color: #42b983; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createApp } from 'vue'; | ||
import App from './App.vue'; | ||
|
||
createApp(App).mount('#app'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"strict": true, | ||
"module": "es2015", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": [ | ||
"./**/*.ts" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,7 @@ class WebpackConfig { | |
this.babelTypeScriptPresetOptions = {}; | ||
this.vueOptions = { | ||
useJsx: false, | ||
version: null, | ||
}; | ||
this.eslintOptions = { | ||
lintVue: false, | ||
|
@@ -749,9 +750,21 @@ class WebpackConfig { | |
if (!(key in this.vueOptions)) { | ||
throw new Error(`"${key}" is not a valid key for enableVueLoader(). Valid keys: ${Object.keys(this.vueOptions).join(', ')}.`); | ||
} | ||
|
||
if (key === 'version') { | ||
const validVersions = [2, 3]; | ||
if (!validVersions.includes(vueOptions.version)) { | ||
throw new Error(`"${vueOptions.version}" is not a valid value for the "version" option passed to enableVueLoader(). Valid versions are: ${validVersions.join(', ')}.`); | ||
} | ||
} | ||
|
||
this.vueOptions[key] = vueOptions[key]; | ||
} | ||
|
||
this.vueOptions = vueOptions; | ||
// useJsx and vue 3 are not currently supported by Encore | ||
if (this.vueOptions.useJsx && this.vueOptions.version === 3) { | ||
throw new Error('Setting both "useJsx: true" and "version: 3" for enableVueLoader() is not currently supported. Please use version: 2 or disable useJsx.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that the babel preset that enables this doesn't work yet - vuejs/jsx-vue2#106 |
||
} | ||
|
||
enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}, eslintOptions = {}) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,17 +87,28 @@ const features = { | |
], | ||
description: 'process TypeScript files with Babel' | ||
}, | ||
vue: { | ||
vue2: { | ||
method: 'enableVueLoader()', | ||
// vue is needed so the end-user can do things | ||
// vue-template-compiler is a peer dep of vue-loader | ||
packages: [ | ||
{ name: 'vue' }, | ||
{ name: 'vue-loader', enforce_version: true }, | ||
{ name: 'vue', version: '^2.5' }, | ||
{ name: 'vue-loader', version: '^15' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New feature to force what version to show when we recommend something to the user. Causes |
||
{ name: 'vue-template-compiler' } | ||
], | ||
description: 'load Vue files' | ||
}, | ||
vue3: { | ||
method: 'enableVueLoader()', | ||
// vue is needed so the end-user can do things | ||
// @vue/compiler-sfc is an optional peer dep of vue-loader | ||
packages: [ | ||
{ name: 'vue', enforce_version: true }, | ||
{ name: 'vue-loader', enforce_version: true }, | ||
{ name: '@vue/compiler-sfc' } | ||
], | ||
description: 'load Vue files' | ||
}, | ||
'vue-jsx': { | ||
method: 'enableVueLoader()', | ||
packages: [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The re-ordering works around a vue-loader bug - which was just merged :) vuejs/vue-loader#1671