mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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",
|
"esm": "^3.2.0",
|
||||||
"execa": "^1.0.0",
|
"execa": "^1.0.0",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
|
"opener": "1.5.1",
|
||||||
"pretty-bytes": "^5.1.0",
|
"pretty-bytes": "^5.1.0",
|
||||||
"std-env": "^2.2.1",
|
"std-env": "^2.2.1",
|
||||||
"wrap-ansi": "^4.0.0"
|
"wrap-ansi": "^4.0.0"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
|
import opener from 'opener'
|
||||||
import { common, server } from '../options'
|
import { common, server } from '../options'
|
||||||
import { showBanner, eventsMapping, formatPath } from '../utils'
|
import { showBanner, eventsMapping, formatPath } from '../utils'
|
||||||
|
|
||||||
@ -9,17 +10,31 @@ export default {
|
|||||||
usage: 'dev <dir>',
|
usage: 'dev <dir>',
|
||||||
options: {
|
options: {
|
||||||
...common,
|
...common,
|
||||||
...server
|
...server,
|
||||||
|
open: {
|
||||||
|
alias: 'o',
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Opens the server listeners url in the default browser'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async run(cmd) {
|
async run(cmd) {
|
||||||
const { argv } = 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) {
|
async startDev(cmd, argv) {
|
||||||
try {
|
try {
|
||||||
await this._startDev(cmd, argv)
|
const nuxt = await this._startDev(cmd, argv)
|
||||||
|
|
||||||
|
return nuxt
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
consola.error(error)
|
consola.error(error)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user