Run react app locally in production mode using vite?
Asked Answered
P

1

9

I would like to run a vite react app locally in production mode? What is the best way of doing it?

Polly answered 9/2, 2023 at 4:42 Comment(3)
yarn build? then move the out/build folder into your local serverDinothere
You can create a prod build and run npx serve command from the dist/build directory.Benthamism
Thanks @RahulSharma for you hints. Its working now, putting the solution the answer section.Polly
P
11

Go to package.json file of you vite react app.

modify your script like that :

{
  "scripts": {
    "build": "vite build",
    "serve": "vite preview"
  }
}

then run :

npm run build

npm run serve
Polly answered 9/2, 2023 at 6:25 Comment(3)
Please note that viet preview isn't meant for production mode!Halter
@Halter could you please describe your statement bit more?Polly
See Vite documentation: "It is important to note that vite preview is intended for previewing the build locally and not meant as a production server."Halter

© 2022 - 2024 — McMap. All rights reserved.