How to set vite (preview) production port?
Asked Answered
O

3

25

I have been looking arround on how to set a production port for vite but I can't find way I have tried this vite js config

  server: {
    host: true,
  },
  preview:{
    port:5005
  }

but it seems like it can't work

Onieonion answered 22/12, 2021 at 8:58 Comment(1)
You use server.host instead of server.port. I know this is old, but noone mentioned this before.. Maybe it helps somebody with the same trouble :)Chapiter
O
41

According to documentation this should work

export default defineConfig({
  server: {
    port: 3030
  },
  preview: {
    port: 8080
  }
})

But if it doesn't work add --port on preview command in package.json

"scripts": {
    "serve": "vite preview --port 6000"
  },
Onieonion answered 22/12, 2021 at 8:58 Comment(0)
D
10

In package.json, add this code

"scripts": {
    "serve": "vite --port 8000"
},

In terminal, run the command

npm run serve
Deron answered 19/2, 2022 at 19:7 Comment(0)
F
3

just update you npm run dev command to:

"dev": "vite --port=8080"

in the package.json file

Fanestil answered 21/8, 2023 at 11:47 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Brahmanism

© 2022 - 2024 — McMap. All rights reserved.