Skip to content

Commit 1869aa2

Browse files
committed
feat: Generator now supports template inheritance
1 parent b878767 commit 1869aa2

File tree

14 files changed

+96
-124
lines changed

14 files changed

+96
-124
lines changed

packages/@vue/cli-plugin-typescript/__tests__/tsPluginE2e.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('cypress', async () => {
1313
})
1414

1515
test('cypress with router', async () => {
16-
const project = await create('ts-e2e-cypress', {
16+
const project = await create('ts-e2e-cypress-router', {
1717
router: true,
1818
plugins: {
1919
'@vue/cli-plugin-typescript': {},
Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
<%_ if (!rootOptions.router) { _%>
2-
<template>
3-
<div id="app">
4-
<img src="./assets/logo.png">
5-
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
6-
</div>
7-
</template>
1+
---
2+
extend: '@vue/cli-service/generator/template/src/App.vue'
3+
replace:
4+
- !!js/regexp /Welcome to Your Vue\.js App/
5+
- !!js/regexp /<script>[^]*?<\/script>/
6+
---
87
8+
<%# REPLACE %>
9+
Welcome to Your Vue.js + TypeScript App
10+
<%# END_REPLACE %>
11+
12+
<%# REPLACE %>
913
<script lang="ts">
10-
<%_ if (!options.classComponent) { _%>
14+
<%_ if (!options.classComponent) { _%>
1115
import Vue from 'vue';
1216
import HelloWorld from './components/HelloWorld.vue';
1317
@@ -17,7 +21,7 @@ export default Vue.extend({
1721
HelloWorld
1822
}
1923
});
20-
<%_ } else { _%>
24+
<%_ } else { _%>
2125
import { Component, Vue } from 'vue-property-decorator';
2226
import HelloWorld from './components/HelloWorld.vue';
2327
@@ -27,44 +31,6 @@ import HelloWorld from './components/HelloWorld.vue';
2731
},
2832
})
2933
export default class App extends Vue {}
30-
<%_ } _%>
31-
</script>
32-
<%_ } else { _%>
33-
<template>
34-
<div id="app">
35-
<div id="nav">
36-
<router-link to="/">Home</router-link> |
37-
<router-link to="/about">About</router-link>
38-
</div>
39-
<router-view/>
40-
</div>
41-
</template>
42-
<%_ } _%>
43-
44-
<style>
45-
#app {
46-
font-family: 'Avenir', Helvetica, Arial, sans-serif;
47-
-webkit-font-smoothing: antialiased;
48-
-moz-osx-font-smoothing: grayscale;
49-
text-align: center;
50-
color: #2c3e50;
51-
<%_ if (!rootOptions.router) { _%>
52-
margin-top: 60px;
53-
<%_ } _%>
54-
}
55-
<%_ if (rootOptions.router) { _%>
56-
57-
#nav {
58-
padding: 30px;
59-
}
60-
61-
#nav a {
62-
font-weight: bold;
63-
color: #2c3e50;
64-
}
65-
66-
#nav a.router-link-exact-active {
67-
color: #42b983;
68-
}
6934
<%_ } _%>
70-
</style>
35+
</script>
36+
<%# END_REPLACE %>
Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,7 @@
1-
<template>
2-
<div class="hello">
3-
<h1>{{ msg }}</h1>
4-
<p>
5-
For guide and recipes on how to configure / customize this project,<br>
6-
check out the
7-
<a href="https://github.com/vuejs/vue-cli/tree/dev/docs" target="_blank">vue-cli documentation</a>.
8-
</p>
9-
<h3>Installed CLI Plugins</h3>
10-
<ul>
11-
<%_ for (plugin of plugins) { _%>
12-
<li><a href="<%- plugin.link %>" target="_blank"><%- plugin.name %></a></li>
13-
<%_ } _%>
14-
</ul>
15-
<h3>Essential Links</h3>
16-
<ul>
17-
<li><a href="https://vuejs.org" target="_blank">Core Docs</a></li>
18-
<li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li>
19-
<li><a href="https://chat.vuejs.org" target="_blank">Community Chat</a></li>
20-
<li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li>
21-
</ul>
22-
<h3>Ecosystem</h3>
23-
<ul>
24-
<li><a href="https://router.vuejs.org/en/essentials/getting-started.html" target="_blank">vue-router</a></li>
25-
<li><a href="https://vuex.vuejs.org/en/intro.html" target="_blank">vuex</a></li>
26-
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank">vue-devtools</a></li>
27-
<li><a href="https://vue-loader.vuejs.org/en" target="_blank">vue-loader</a></li>
28-
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank">awesome-vue</a></li>
29-
</ul>
30-
</div>
31-
</template>
32-
1+
---
2+
extend: '@vue/cli-service/generator/template/src/components/HelloWorld.vue'
3+
replace: !!js/regexp /<script>[^]*?<\/script>/
4+
---
335
<script lang="ts">
346
<%_ if (!options.classComponent) { _%>
357
import Vue from 'vue';
@@ -49,21 +21,3 @@ export default class HelloWorld extends Vue {
4921
}
5022
<%_ } _%>
5123
</script>
52-
53-
<!-- Add "scoped" attribute to limit CSS to this component only -->
54-
<style scoped>
55-
h3 {
56-
margin: 40px 0 0;
57-
}
58-
ul {
59-
list-style-type: none;
60-
padding: 0;
61-
}
62-
li {
63-
display: inline-block;
64-
margin: 0 10px;
65-
}
66-
a {
67-
color: #42b983;
68-
}
69-
</style>

packages/@vue/cli-plugin-typescript/generator/template/src/views/Home.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<%_ if (rootOptions.router) { _%>
2-
<template>
3-
<div class="home">
4-
<img src="../assets/logo.png">
5-
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
6-
</div>
7-
</template>
1+
---
2+
extend: '@vue/cli-service/generator/template/src/views/Home.vue'
3+
replace:
4+
- !!js/regexp /Welcome to Your Vue\.js App/
5+
- !!js/regexp /<script>[^]*?<\/script>/
6+
---
87
8+
<%# REPLACE %>
9+
Welcome to Your Vue.js + TypeScript App
10+
<%# END_REPLACE %>
11+
12+
<%# REPLACE %>
913
<script lang="ts">
1014
<%_ if (!options.classComponent) { _%>
1115
import Vue from 'vue';
@@ -29,4 +33,4 @@ import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
2933
export default class Home extends Vue {}
3034
<%_ } _%>
3135
</script>
32-
<%_ } _%>
36+
<%# END_REPLACE %>

packages/@vue/cli-service/generator/template/public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
77
<link rel="shortcut icon" href="<%%= webpackConfig.output.publicPath %%>favicon.ico">
8-
<title><%= options.projectName %></title>
8+
<title><%= rootOptions.projectName %></title>
99
</head>
1010
<body>
1111
<noscript>
12-
<strong>We're sorry but <%= options.projectName %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
12+
<strong>We're sorry but <%= rootOptions.projectName %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1313
</noscript>
1414
<div id="app"></div>
1515
<!-- built files will be auto injected -->

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%_ if (!options.router) { _%>
1+
<%_ if (!rootOptions.router) { _%>
22
<template>
33
<div id="app">
44
<img src="./assets/logo.png">
@@ -35,11 +35,11 @@ export default {
3535
-moz-osx-font-smoothing: grayscale;
3636
text-align: center;
3737
color: #2c3e50;
38-
<%_ if (!options.router) { _%>
38+
<%_ if (!rootOptions.router) { _%>
3939
margin-top: 60px;
4040
<%_ } _%>
4141
}
42-
<%_ if (options.router) { _%>
42+
<%_ if (rootOptions.router) { _%>
4343

4444
#nav {
4545
padding: 30px;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import Vue from 'vue'
22
import App from './App.vue'
3-
<%_ if (options.router) { _%>
3+
<%_ if (rootOptions.router) { _%>
44
import router from './router'
55
<%_ } _%>
6-
<%_ if (options.vuex) { _%>
6+
<%_ if (rootOptions.vuex) { _%>
77
import store from './store'
88
<%_ } _%>
99

1010
Vue.config.productionTip = false
1111

1212
new Vue({
13-
<%_ if (options.router) { _%>
13+
<%_ if (rootOptions.router) { _%>
1414
router,
1515
<%_ } _%>
16-
<%_ if (options.vuex) { _%>
16+
<%_ if (rootOptions.vuex) { _%>
1717
store,
1818
<%_ } _%>
1919
render: h => h(App)

packages/@vue/cli-service/generator/template/src/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%_ if (options.router) { _%>
1+
<%_ if (rootOptions.router) { _%>
22
import Vue from 'vue'
33
import Router from 'vue-router'
44
import Home from './views/Home.vue'

packages/@vue/cli-service/generator/template/src/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%_ if (options.vuex) { _%>
1+
<%_ if (rootOptions.vuex) { _%>
22
import Vue from 'vue'
33
import Vuex from 'vuex'
44

packages/@vue/cli-service/generator/template/src/views/About.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%_ if (options.router) { _%>
1+
<%_ if (rootOptions.router) { _%>
22
<template>
33
<div class="about">
44
<h1>This is an about page</h1>

0 commit comments

Comments
 (0)