Skip to content

Commit d75ea99

Browse files
committed
feat: make it possible to opt-out of Babel
close #1199
1 parent 1835755 commit d75ea99

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ module.exports = class Creator {
314314
type: 'checkbox',
315315
message: 'Check the features needed for your project:',
316316
choices: [],
317-
pageSize: 8
317+
pageSize: 10
318318
}
319319
return {
320320
presetPrompt,

packages/@vue/cli/lib/promptModules/__tests__/babel.spec.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('should pass', async () => {
99
const expectedPrompts = [
1010
{
1111
message: 'features',
12-
check: []
12+
check: [0]
1313
}
1414
]
1515

@@ -27,7 +27,36 @@ test('should pass', async () => {
2727
)
2828
})
2929

30-
test('should not include the plugin if ts is also present', async () => {
30+
test('with TS', async () => {
31+
const mockTSModule = api => {
32+
api.onPromptComplete(answers => {
33+
answers.useTsWithBabel = true
34+
answers.features.push('ts')
35+
})
36+
}
37+
38+
const expectedPrompts = [
39+
{
40+
message: 'features',
41+
check: [] // no need to check if "useTsWithBabel" is explicitly true
42+
}
43+
]
44+
45+
const expectedOptions = {
46+
plugins: {
47+
'@vue/cli-plugin-babel': {}
48+
}
49+
}
50+
51+
await assertPromptModule(
52+
[mockTSModule, moduleToTest],
53+
expectedPrompts,
54+
expectedOptions,
55+
{ pluginsOnly: true }
56+
)
57+
})
58+
59+
test('with TS, no Babel', async () => {
3160
const mockTSModule = api => {
3261
api.onPromptComplete(answers => {
3362
answers.features.push('ts')
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
module.exports = cli => {
2+
cli.injectFeature({
3+
name: 'Babel',
4+
value: 'babel',
5+
short: 'Babel',
6+
checked: true
7+
})
8+
29
cli.onPromptComplete((answers, options) => {
3-
if (
4-
!answers.features.includes('ts') ||
5-
answers.useTsWithBabel ||
6-
answers.experimentalCompileTsWithBabel
7-
) {
8-
options.plugins['@vue/cli-plugin-babel'] = {}
10+
if (answers.features.includes('ts')) {
11+
if (!answers.useTsWithBabel && !answers.experimentalCompileTsWithBabel) {
12+
return
13+
}
14+
} else {
15+
if (!answers.features.includes('babel')) {
16+
return
17+
}
918
}
19+
options.plugins['@vue/cli-plugin-babel'] = {}
1020
})
1121
}

packages/@vue/cli/lib/promptModules/linter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = cli => {
55
cli.injectFeature({
66
name: 'Linter / Formatter',
77
value: 'linter',
8-
short: 'Linter'
8+
short: 'Linter',
9+
checked: true
910
})
1011

1112
cli.injectPrompt({

packages/@vue/cli/lib/promptModules/typescript.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ module.exports = cli => {
2626
name: 'useTsWithBabel',
2727
when: answers => answers.features.includes('ts'),
2828
type: 'confirm',
29-
message: 'Use Babel alongside TypeScript for auto-detected polyfills?'
29+
message: 'Use Babel alongside TypeScript for auto-detected polyfills?',
30+
default: answers => answers.features.includes('babel')
3031
})
3132
}
3233

0 commit comments

Comments
 (0)