Skip to content

Commit

Permalink
fix: fix duplicate id="app" in Vue 3 project template (#5852)
Browse files Browse the repository at this point in the history
closes #5813
  • Loading branch information
sodatea committed Sep 8, 2020
1 parent d6e493d commit 34c09dc
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
Expand Up @@ -85,6 +85,8 @@ test('use with Vue 3', async () => {

expect(files['src/main.js']).toMatch('.use(router)')

expect(files['src/App.vue']).not.toMatch('<div id="app">')

expect(pkg.dependencies).toHaveProperty('vue-router')
expect(pkg.dependencies['vue-router']).toMatch('^4')
})
Expand Down
@@ -0,0 +1,63 @@
---
extend: '@vue/cli-service/generator/template/src/App.vue'
replace:
- !!js/regexp /<template>[^]*?<\/template>/
- !!js/regexp /\n<script>[^]*?<\/script>\n/
- !!js/regexp / margin-top[^]*?<\/style>/
---
<%# REPLACE %>
<template>
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view/>
</template>
<%# END_REPLACE %>
<%# REPLACE %>
<%# END_REPLACE %>
<%# REPLACE %>
}
<%_ if (rootOptions.cssPreprocessor !== 'stylus') { _%>
<%_ if (!rootOptions.cssPreprocessor) { _%>
#nav {
padding: 30px;
}
#nav a {
font-weight: bold;
color: #2c3e50;
}
#nav a.router-link-exact-active {
color: #42b983;
}
<%_ } else { _%>
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
<%_ } _%>
<%_ } else { _%>
#nav
padding 30px
a
font-weight bold
color #2c3e50
&.router-link-exact-active
color #42b983
<%_ } _%>
</style>
<%# END_REPLACE %>
2 changes: 2 additions & 0 deletions packages/@vue/cli-service/__tests__/generator.spec.js
Expand Up @@ -46,4 +46,6 @@ test('Vue 3', async () => {
expect(pkg).toHaveProperty(['devDependencies', '@vue/compiler-sfc'])

expect(files['src/main.js']).toMatch(`import { createApp } from 'vue'`)

expect(files['src/App.vue']).not.toMatch('<div id="app">')
})
4 changes: 1 addition & 3 deletions packages/@vue/cli-service/generator/index.js
@@ -1,11 +1,9 @@
module.exports = (api, options) => {
const isVue3 = (options.vueVersion === '3')
api.render('./template', {
isVue3,
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
})

if (isVue3) {
if (options.vueVersion === '3') {
api.extendPackage({
dependencies: {
'vue': '^3.0.0-0'
Expand Down
9 changes: 9 additions & 0 deletions packages/@vue/cli-service/generator/template/src/App.vue
@@ -1,4 +1,12 @@
<template>
<%_ if (rootOptions.vueVersion === '3') { _%>
<img alt="Vue logo" src="./assets/logo.png">
<%_ if (!rootOptions.bare) { _%>
<HelloWorld msg="Welcome to Your Vue.js App"/>
<%_ } else { _%>
<h1>Welcome to Your Vue.js App</h1>
<%_ } _%>
<%_ } else { _%>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<%_ if (!rootOptions.bare) { _%>
Expand All @@ -7,6 +15,7 @@
<h1>Welcome to Your Vue.js App</h1>
<%_ } _%>
</div>
<%_ } _%>
</template>
<%_ if (!rootOptions.bare) { _%>

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/generator/template/src/main.js
@@ -1,4 +1,4 @@
<%_ if (isVue3) { _%>
<%_ if (rootOptions.vueVersion === '3') { _%>
import { createApp } from 'vue'
import App from './App.vue'

Expand Down

0 comments on commit 34c09dc

Please sign in to comment.