diff --git a/docs/guide/cli-service.md b/docs/guide/cli-service.md index 7699250034..d944fbc81a 100644 --- a/docs/guide/cli-service.md +++ b/docs/guide/cli-service.md @@ -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`. diff --git a/packages/@vue/cli-service/lib/commands/serve.js b/packages/@vue/cli-service/lib/commands/serve.js index d1eec4a0f7..0852171c5b 100644 --- a/packages/@vue/cli-service/lib/commands/serve.js +++ b/packages/@vue/cli-service/lib/commands/serve.js @@ -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