Skip to content

Commit 7c19dd6

Browse files
cexbrayathaoqunjiang
authored andcommitted
fix: do not generate empty file when use ts without router (#4374)
(cherry picked from commit 52bae8e)
1 parent bb2e3e7 commit 7c19dd6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ test('generate files', async () => {
1717
expect(files['src/main.ts']).toBeTruthy()
1818
expect(files['src/main.js']).toBeFalsy()
1919
expect(files['src/App.vue']).toMatch('<script lang="ts">')
20+
// checks that the Home.vue file has not been created, even empty
21+
expect(files.hasOwnProperty('src/views/Home.vue')).toBeFalsy()
2022
})
2123

2224
test('classComponent', async () => {
@@ -62,6 +64,22 @@ test('use with Babel', async () => {
6264
expect(files['tsconfig.json']).toMatch(`"target": "esnext"`)
6365
})
6466

67+
test('use with router', async () => {
68+
const { files } = await generateWithPlugin([
69+
{
70+
id: '@vue/cli-plugin-router',
71+
apply: require('@vue/cli-plugin-router/generator'),
72+
options: {}
73+
},
74+
{
75+
id: 'ts',
76+
apply: require('../generator'),
77+
options: {}
78+
}
79+
])
80+
expect(files['src/views/Home.vue']).toMatch('<div class=\"home\">')
81+
})
82+
6583
test('lint', async () => {
6684
const { pkg, files } = await generateWithPlugin([
6785
{

packages/@vue/cli/lib/GeneratorAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function renderFile (name, data, ejsOptions) {
412412
// if evaluated to falsy value, return early to avoid extra cost for extend expression
413413
const result = ejs.render(finalTemplate, data, ejsOptions)
414414
if (!result) {
415-
return
415+
return ''
416416
}
417417
}
418418

0 commit comments

Comments
 (0)