VueJS 3 + Vite修改默认服务端口

Vite启动出现本地端口被拒绝的错误:

$ vite
error when starting dev server:
Error: listen EACCES: permission denied 127.0.0.1:3000
    at Server.setupListenHandle [as _listen2] (net.js:1301:21)
    at listenInCluster (net.js:1366:12)
    at doListen (net.js:1503:7)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

修改一下端口,找到vite.config.js,在server{}区块中添加port参数,参考如下:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server:{
    port: 5000
  }
})

重新启动,成功启动Vite服务

yarn dev
yarn run v1.21.0
warning package.json: No license field
$ vite

  vite v2.6.7 dev server running at:

  > Local: http://localhost:5000/
  > Network: use `--host` to expose

  ready in 522ms.

参考资料:https://cn.vitejs.dev/config/#server-port

Post Comment