feat(cli): add `--devtools` option for build and generate (#4357)

This commit is contained in:
Yuki Takemoto 2018-11-18 08:05:51 +09:00 committed by Clark Du
parent 33d4e89925
commit e6f73b596a
4 changed files with 61 additions and 0 deletions

View File

@ -19,6 +19,18 @@ export default {
}
}
},
devtools: {
type: 'boolean',
default: false,
description: 'Enable Vue devtools',
prepare(cmd, options, argv) {
options.vue = options.vue || {}
options.vue.config = options.vue.config || {}
if (argv.devtools) {
options.vue.config.devtools = true
}
}
},
generate: {
type: 'boolean',
default: true,

View File

@ -12,6 +12,18 @@ export default {
default: true,
description: 'Only generate pages for dynamic routes. Nuxt has to be built once before using this option'
},
devtools: {
type: 'boolean',
default: false,
description: 'Enable Vue devtools',
prepare(cmd, options, argv) {
options.vue = options.vue || {}
options.vue.config = options.vue.config || {}
if (argv.devtools) {
options.vue.config.devtools = true
}
}
},
modern: {
...common.modern,
description: 'Generate app in modern build (modern mode can be only client)',

View File

@ -44,6 +44,25 @@ describe('build', () => {
expect(process.exit).toHaveBeenCalled()
})
test('build with devtools', async () => {
mockGetNuxt({
mode: 'universal'
})
const builder = mockGetBuilder(Promise.resolve())
const cmd = NuxtCommand.from(build)
const args = ['build', '.', '--devtools']
const argv = cmd.getArgv(args)
argv._ = ['.']
const options = await cmd.getNuxtConfig(argv)
await cmd.run()
expect(options.vue.config.devtools).toBe(true)
expect(builder).toHaveBeenCalled()
})
test('catches error', async () => {
mockGetNuxt({ mode: 'universal' })
mockGetBuilder(Promise.reject(new Error('Builder Error')))

View File

@ -46,6 +46,24 @@ describe('generate', () => {
Command.prototype.getArgv = getArgv
})
test('build with devtools', async () => {
mockGetNuxt()
const generator = mockGetGenerator(Promise.resolve())
const cmd = NuxtCommand.from(generate)
const args = ['generate', '.', '--devtools']
const argv = cmd.getArgv(args)
argv._ = ['.']
const options = await cmd.getNuxtConfig(argv)
await cmd.run()
expect(options.vue.config.devtools).toBe(true)
expect(generator).toHaveBeenCalled()
expect(generator.mock.calls[0][0].build).toBe(true)
})
test('catches error', async () => {
mockGetNuxt()
mockGetGenerator(Promise.reject(new Error('Generator Error')))