You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev-guide/plugin-dev.md
+50-1
Original file line number
Diff line number
Diff line change
@@ -430,7 +430,56 @@ This is because the command's expected mode needs to be known before loading env
430
430
431
431
Prompts are required to handle user choices when creating a new project or adding a new plugin to the existing one. All prompts logic is stored inside the `prompts.js` file. The prompts are presented using [inquirer](https://github.com/SBoudrias/Inquirer.js) under the hood.
432
432
433
-
When user initialize the plugin by calling `vue invoke`, if the plugin contains a `prompts.js` in its root directory, it will be used during invocation. The file should export an array of [Questions](https://github.com/SBoudrias/Inquirer.js#question) that will be handled by Inquirer.js. The resolved answers object will be passed to the plugin's generator as options.
433
+
When user initialize the plugin by calling `vue invoke`, if the plugin contains a `prompts.js` in its root directory, it will be used during invocation. The file should export an array of [Questions](https://github.com/SBoudrias/Inquirer.js#question) that will be handled by Inquirer.js.
434
+
435
+
You should export directly array of questions, or export function that return those.
436
+
437
+
e.g. directly array of questions:
438
+
```js
439
+
// prompts.js
440
+
441
+
module.exports= [
442
+
{
443
+
type:'input',
444
+
name:'locale',
445
+
message:'The locale of project localization.',
446
+
validate:input=>!!input,
447
+
default:'en'
448
+
},
449
+
// ...
450
+
]
451
+
```
452
+
453
+
e.g. function that return array of questions:
454
+
```js
455
+
// prompts.js
456
+
457
+
// pass `package.json` of project to function argument
458
+
module.exports=pkg=> {
459
+
constprompts= [
460
+
{
461
+
type:'input',
462
+
name:'locale',
463
+
message:'The locale of project localization.',
464
+
validate:input=>!!input,
465
+
default:'en'
466
+
}
467
+
]
468
+
469
+
// add dynamically propmpt
470
+
if ('@vue/cli-plugin-eslint'in (pkg.devDependencies|| {})) {
471
+
prompts.push({
472
+
type:'confirm',
473
+
name:'useESLintPluginVueI18n',
474
+
message:'Use ESLint plugin for Vue I18n ?'
475
+
})
476
+
}
477
+
478
+
return prompts
479
+
}
480
+
```
481
+
482
+
The resolved answers object will be passed to the plugin's generator as options.
434
483
435
484
Alternatively, the user can skip the prompts and directly initialize the plugin by passing options via the command line, e.g.:
0 commit comments