Skip to content

Commit

Permalink
feat: add --copy option for vue-cli-service serve (vuejs#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
morrislaptop authored and yyx990803 committed May 29, 2018
1 parent 3bcc511 commit 5e95b3d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/cli-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Usage: vue-cli-service serve [options]
Options:
--open open browser on server start
--copy copy url to clipboard on server start
--mode specify env mode (default: development)
--host specify host (default: 0.0.0.0)
--port specify port (default: 8080)
Expand Down
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ serve a .js or .vue file in development mode with zero config
Options:
-o, --open Open browser
-c, --copy Copy local url to clipboard
-h, --help output usage information
```

Expand Down
8 changes: 7 additions & 1 deletion packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,16 @@ module.exports = (api, options) => {
return
}

let copied = ''
if (isFirstCompile && args.copy) {
require('clipboardy').write(urls.localUrlForBrowser)
copied = chalk.dim('(copied to clipboard)')
}

console.log()
console.log([
` App running at:`,
` - Local: ${chalk.cyan(urls.localUrlForTerminal)}`,
` - Local: ${chalk.cyan(urls.localUrlForTerminal)} ${copied}`,
` - Network: ${chalk.cyan(urls.lanUrlForTerminal)}`
].join('\n'))
console.log()
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"cache-loader": "^1.2.2",
"case-sensitive-paths-webpack-plugin": "^2.1.2",
"chalk": "^2.4.1",
"clipboardy": "^1.2.3",
"cliui": "^4.1.0",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ program
.command('serve [entry]')
.description('serve a .js or .vue file in development mode with zero config')
.option('-o, --open', 'Open browser')
.option('-c, --copy', 'Copy local url to clipboard')
.action((entry, cmd) => {
loadCommand('serve', '@vue/cli-service-global').serve(entry, cleanArgs(cmd))
})
Expand Down

0 comments on commit 5e95b3d

Please sign in to comment.