mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-09 03:03:18 +00:00
feat(cli): option to open the project in the browser (#4930)
This commit is contained in:
parent
3147823dee
commit
4c7bd9c507
@ -19,6 +19,7 @@
|
||||
"esm": "^3.2.0",
|
||||
"execa": "^1.0.0",
|
||||
"minimist": "^1.2.0",
|
||||
"opener": "1.5.1",
|
||||
"pretty-bytes": "^5.1.0",
|
||||
"std-env": "^2.2.1",
|
||||
"wrap-ansi": "^4.0.0"
|
||||
|
@ -1,5 +1,6 @@
|
||||
import consola from 'consola'
|
||||
import chalk from 'chalk'
|
||||
import opener from 'opener'
|
||||
import { common, server } from '../options'
|
||||
import { showBanner, eventsMapping, formatPath } from '../utils'
|
||||
|
||||
@ -9,17 +10,31 @@ export default {
|
||||
usage: 'dev <dir>',
|
||||
options: {
|
||||
...common,
|
||||
...server
|
||||
...server,
|
||||
open: {
|
||||
alias: 'o',
|
||||
type: 'boolean',
|
||||
description: 'Opens the server listeners url in the default browser'
|
||||
}
|
||||
},
|
||||
|
||||
async run(cmd) {
|
||||
const { argv } = cmd
|
||||
await this.startDev(cmd, argv)
|
||||
const nuxt = await this.startDev(cmd, argv)
|
||||
|
||||
// Opens the server listeners url in the default browser
|
||||
if (argv.open) {
|
||||
for (const listener of nuxt.server.listeners) {
|
||||
await opener(listener.url)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async startDev(cmd, argv) {
|
||||
try {
|
||||
await this._startDev(cmd, argv)
|
||||
const nuxt = await this._startDev(cmd, argv)
|
||||
|
||||
return nuxt
|
||||
} catch (error) {
|
||||
consola.error(error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user