Skip to content

fix(cli-service): catch exception if "copy to clipboard" fails (issue #3476) #3503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/guide/cli-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ Options:
--https use https (default: false)
```

::: tip --copy
Copying to clipboard might not work on a few platforms.
If copying was successful, `(copied to clipboard)` is displayed next to the local dev server URL.
:::

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.

In addition to the command line flags, you can also configure the dev server using the [devServer](../config/#devserver) field in `vue.config.js`.
Expand Down
8 changes: 6 additions & 2 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ module.exports = (api, options) => {

let copied = ''
if (isFirstCompile && args.copy) {
require('clipboardy').write(urls.localUrlForBrowser)
copied = chalk.dim('(copied to clipboard)')
try {
require('clipboardy').writeSync(urls.localUrlForBrowser)
copied = chalk.dim('(copied to clipboard)')
} catch (_) {
/* catch exception if copy to clipboard isn't supported (e.g. WSL), see issue #3476 */
}
}

const networkUrl = publicUrl
Expand Down