From a581b2e651e944fb54f376f35a922db2b0378997 Mon Sep 17 00:00:00 2001 From: tanghui Date: Mon, 20 Dec 2021 19:50:31 +0800 Subject: [PATCH 1/2] fix: fix #6834 --- packages/@vue/cli-service/lib/commands/serve.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/serve.js b/packages/@vue/cli-service/lib/commands/serve.js index 3c5bc9648d..5e70967504 100644 --- a/packages/@vue/cli-service/lib/commands/serve.js +++ b/packages/@vue/cli-service/lib/commands/serve.js @@ -3,7 +3,8 @@ const { error, hasProjectYarn, hasProjectPnpm, - IpcMessenger + IpcMessenger, + openBrowser } = require('@vue/cli-shared-utils') const defaults = { @@ -179,6 +180,8 @@ module.exports = (api, options) => { process.exit(1) }) + const open = args.open || projectDevServerOptions.open + // create server const server = new WebpackDevServer(Object.assign({ historyApiFallback: { @@ -216,7 +219,7 @@ module.exports = (api, options) => { ...projectDevServerOptions.client }, - open: args.open || projectDevServerOptions.open, + // open, setupExitSignals: true, // eslint-disable-next-line no-shadow @@ -288,6 +291,9 @@ module.exports = (api, options) => { console.log(` - Local: ${chalk.cyan(urls.localUrlForTerminal)} ${copied}`) if (!isInContainer) { console.log(` - Network: ${chalk.cyan(networkUrl)}`) + if (open) { + openBrowser(urls.localUrlForTerminal) + } } else { console.log() console.log(chalk.yellow(` It seems you are running Vue CLI inside a container.`)) From e47b30572c232755719a46d736936b9f8e3cc3d0 Mon Sep 17 00:00:00 2001 From: tanghui Date: Mon, 20 Dec 2021 20:02:49 +0800 Subject: [PATCH 2/2] fix: fire once --- packages/@vue/cli-service/lib/commands/serve.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/serve.js b/packages/@vue/cli-service/lib/commands/serve.js index 5e70967504..87d23e7863 100644 --- a/packages/@vue/cli-service/lib/commands/serve.js +++ b/packages/@vue/cli-service/lib/commands/serve.js @@ -291,9 +291,6 @@ module.exports = (api, options) => { console.log(` - Local: ${chalk.cyan(urls.localUrlForTerminal)} ${copied}`) if (!isInContainer) { console.log(` - Network: ${chalk.cyan(networkUrl)}`) - if (open) { - openBrowser(urls.localUrlForTerminal) - } } else { console.log() console.log(chalk.yellow(` It seems you are running Vue CLI inside a container.`)) @@ -317,6 +314,9 @@ module.exports = (api, options) => { const buildCommand = hasProjectYarn(api.getCwd()) ? `yarn build` : hasProjectPnpm(api.getCwd()) ? `pnpm run build` : `npm run build` console.log(` Note that the development build is not optimized.`) console.log(` To create a production build, run ${chalk.cyan(buildCommand)}.`) + if (open) { + openBrowser(urls.localUrlForTerminal) + } } else { console.log(` App is served in production mode.`) console.log(` Note this is for preview or E2E testing only.`)