Skip to content

Commit 21256f5

Browse files
LinusBorgAkryum
authored andcommitted
fix(generator): Template files for main.js and router when not using a compiler (#2828)
* fix(cli-service): ES5 compatibility - Don't use arrow function in main.js when not using babel nor typescript. * fix(router): es5 compatibility use normal function instead of arrow function in router.js when neither babel nor typescript are used.
1 parent 6d3c24c commit 21256f5

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

packages/@vue/cli-service/generator/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module.exports = (api, options) => {
2-
api.render('./template')
2+
api.render('./template', {
3+
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
4+
})
35

46
api.extendPackage({
57
scripts: {

packages/@vue/cli-service/generator/router/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = (api, options = {}) => {
77
}
88
})
99
api.render('./template', {
10-
historyMode: options.routerHistoryMode
10+
historyMode: options.routerHistoryMode,
11+
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
1112
})
1213

1314
if (api.invoking) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ export default new Router({
2121
// route level code-splitting
2222
// this generates a separate chunk (about.[hash].js) for this route
2323
// which is lazy-loaded when the route is visited.
24+
<%_ if (doesCompile) { _%>
2425
component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
26+
<%_ } else { _%>
27+
component: function () {
28+
return import(/* webpackChunkName: "about" */ './views/About.vue')
29+
}
30+
<%_ } _%>
2531
}
2632
]
2733
})

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ import App from './App.vue'
44
Vue.config.productionTip = false
55

66
new Vue({
7-
render: h => h(App)
7+
<%_ if (doesCompile) { _%>
8+
render: h => h(App),
9+
<%_ } else { _%>
10+
render: function (h) { return h(App) },
11+
<%_ } _%>
812
}).$mount('#app')

0 commit comments

Comments
 (0)