Skip to content

Commit

Permalink
feat: make it possible to opt-out of Babel
Browse files Browse the repository at this point in the history
close #1199
  • Loading branch information
yyx990803 committed May 11, 2018
1 parent 1835755 commit d75ea99
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ module.exports = class Creator {
type: 'checkbox',
message: 'Check the features needed for your project:',
choices: [],
pageSize: 8
pageSize: 10
}
return {
presetPrompt,
Expand Down
33 changes: 31 additions & 2 deletions packages/@vue/cli/lib/promptModules/__tests__/babel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('should pass', async () => {
const expectedPrompts = [
{
message: 'features',
check: []
check: [0]
}
]

Expand All @@ -27,7 +27,36 @@ test('should pass', async () => {
)
})

test('should not include the plugin if ts is also present', async () => {
test('with TS', async () => {
const mockTSModule = api => {
api.onPromptComplete(answers => {
answers.useTsWithBabel = true
answers.features.push('ts')
})
}

const expectedPrompts = [
{
message: 'features',
check: [] // no need to check if "useTsWithBabel" is explicitly true
}
]

const expectedOptions = {
plugins: {
'@vue/cli-plugin-babel': {}
}
}

await assertPromptModule(
[mockTSModule, moduleToTest],
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})

test('with TS, no Babel', async () => {
const mockTSModule = api => {
api.onPromptComplete(answers => {
answers.features.push('ts')
Expand Down
22 changes: 16 additions & 6 deletions packages/@vue/cli/lib/promptModules/babel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
module.exports = cli => {
cli.injectFeature({
name: 'Babel',
value: 'babel',
short: 'Babel',
checked: true
})

cli.onPromptComplete((answers, options) => {
if (
!answers.features.includes('ts') ||
answers.useTsWithBabel ||
answers.experimentalCompileTsWithBabel
) {
options.plugins['@vue/cli-plugin-babel'] = {}
if (answers.features.includes('ts')) {
if (!answers.useTsWithBabel && !answers.experimentalCompileTsWithBabel) {
return
}
} else {
if (!answers.features.includes('babel')) {
return
}
}
options.plugins['@vue/cli-plugin-babel'] = {}
})
}
3 changes: 2 additions & 1 deletion packages/@vue/cli/lib/promptModules/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = cli => {
cli.injectFeature({
name: 'Linter / Formatter',
value: 'linter',
short: 'Linter'
short: 'Linter',
checked: true
})

cli.injectPrompt({
Expand Down
3 changes: 2 additions & 1 deletion packages/@vue/cli/lib/promptModules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = cli => {
name: 'useTsWithBabel',
when: answers => answers.features.includes('ts'),
type: 'confirm',
message: 'Use Babel alongside TypeScript for auto-detected polyfills?'
message: 'Use Babel alongside TypeScript for auto-detected polyfills?',
default: answers => answers.features.includes('babel')
})
}

Expand Down

0 comments on commit d75ea99

Please sign in to comment.