Skip to content

Commit 34c09dc

Browse files
authored
fix: fix duplicate id="app" in Vue 3 project template (#5852)
closes #5813
1 parent d6e493d commit 34c09dc

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

Diff for: packages/@vue/cli-plugin-router/__tests__/routerGenerator.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ test('use with Vue 3', async () => {
8585

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

88+
expect(files['src/App.vue']).not.toMatch('<div id="app">')
89+
8890
expect(pkg.dependencies).toHaveProperty('vue-router')
8991
expect(pkg.dependencies['vue-router']).toMatch('^4')
9092
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
extend: '@vue/cli-service/generator/template/src/App.vue'
3+
replace:
4+
- !!js/regexp /<template>[^]*?<\/template>/
5+
- !!js/regexp /\n<script>[^]*?<\/script>\n/
6+
- !!js/regexp / margin-top[^]*?<\/style>/
7+
---
8+
9+
<%# REPLACE %>
10+
<template>
11+
<div id="nav">
12+
<router-link to="/">Home</router-link> |
13+
<router-link to="/about">About</router-link>
14+
</div>
15+
<router-view/>
16+
</template>
17+
<%# END_REPLACE %>
18+
19+
<%# REPLACE %>
20+
<%# END_REPLACE %>
21+
22+
<%# REPLACE %>
23+
}
24+
25+
<%_ if (rootOptions.cssPreprocessor !== 'stylus') { _%>
26+
<%_ if (!rootOptions.cssPreprocessor) { _%>
27+
#nav {
28+
padding: 30px;
29+
}
30+
31+
#nav a {
32+
font-weight: bold;
33+
color: #2c3e50;
34+
}
35+
36+
#nav a.router-link-exact-active {
37+
color: #42b983;
38+
}
39+
<%_ } else { _%>
40+
#nav {
41+
padding: 30px;
42+
43+
a {
44+
font-weight: bold;
45+
color: #2c3e50;
46+
47+
&.router-link-exact-active {
48+
color: #42b983;
49+
}
50+
}
51+
}
52+
<%_ } _%>
53+
<%_ } else { _%>
54+
#nav
55+
padding 30px
56+
a
57+
font-weight bold
58+
color #2c3e50
59+
&.router-link-exact-active
60+
color #42b983
61+
<%_ } _%>
62+
</style>
63+
<%# END_REPLACE %>

Diff for: packages/@vue/cli-service/__tests__/generator.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ test('Vue 3', async () => {
4646
expect(pkg).toHaveProperty(['devDependencies', '@vue/compiler-sfc'])
4747

4848
expect(files['src/main.js']).toMatch(`import { createApp } from 'vue'`)
49+
50+
expect(files['src/App.vue']).not.toMatch('<div id="app">')
4951
})

Diff for: packages/@vue/cli-service/generator/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
module.exports = (api, options) => {
2-
const isVue3 = (options.vueVersion === '3')
32
api.render('./template', {
4-
isVue3,
53
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
64
})
75

8-
if (isVue3) {
6+
if (options.vueVersion === '3') {
97
api.extendPackage({
108
dependencies: {
119
'vue': '^3.0.0-0'

Diff for: packages/@vue/cli-service/generator/template/src/App.vue

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<template>
2+
<%_ if (rootOptions.vueVersion === '3') { _%>
3+
<img alt="Vue logo" src="./assets/logo.png">
4+
<%_ if (!rootOptions.bare) { _%>
5+
<HelloWorld msg="Welcome to Your Vue.js App"/>
6+
<%_ } else { _%>
7+
<h1>Welcome to Your Vue.js App</h1>
8+
<%_ } _%>
9+
<%_ } else { _%>
210
<div id="app">
311
<img alt="Vue logo" src="./assets/logo.png">
412
<%_ if (!rootOptions.bare) { _%>
@@ -7,6 +15,7 @@
715
<h1>Welcome to Your Vue.js App</h1>
816
<%_ } _%>
917
</div>
18+
<%_ } _%>
1019
</template>
1120
<%_ if (!rootOptions.bare) { _%>
1221

Diff for: packages/@vue/cli-service/generator/template/src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%_ if (isVue3) { _%>
1+
<%_ if (rootOptions.vueVersion === '3') { _%>
22
import { createApp } from 'vue'
33
import App from './App.vue'
44

0 commit comments

Comments
 (0)