Skip to content

Commit fec38f5

Browse files
jonaskuskehaoqunjiang
authored andcommittedFeb 26, 2019
fix(cli-service): catch exception if "copy to clipboard" fails (issue #3476) (#3503)
close #3476
1 parent 6e9ba9b commit fec38f5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎docs/guide/cli-service.md

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Options:
5252
--https use https (default: false)
5353
```
5454

55+
::: tip --copy
56+
Copying to clipboard might not work on a few platforms.
57+
If copying was successful, `(copied to clipboard)` is displayed next to the local dev server URL.
58+
:::
59+
5560
The `vue-cli-service serve` command starts a dev server (based on [webpack-dev-server](https://github.com/webpack/webpack-dev-server)) that comes with Hot-Module-Replacement (HMR) working out of the box.
5661

5762
In addition to the command line flags, you can also configure the dev server using the [devServer](../config/#devserver) field in `vue.config.js`.

‎packages/@vue/cli-service/lib/commands/serve.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,12 @@ module.exports = (api, options) => {
197197

198198
let copied = ''
199199
if (isFirstCompile && args.copy) {
200-
require('clipboardy').write(urls.localUrlForBrowser)
201-
copied = chalk.dim('(copied to clipboard)')
200+
try {
201+
require('clipboardy').writeSync(urls.localUrlForBrowser)
202+
copied = chalk.dim('(copied to clipboard)')
203+
} catch (_) {
204+
/* catch exception if copy to clipboard isn't supported (e.g. WSL), see issue #3476 */
205+
}
202206
}
203207

204208
const networkUrl = publicUrl

0 commit comments

Comments
 (0)
Please sign in to comment.