Ability to run a real production app and support for SPA
See original GitHub issueDescription
When I am finished making my app and want to build it, I can do npm run build
. Then to run it, I can do npm run serve
, but wait, thats actually not for real production, thats for just previewing it locally. So now I have to make my own node+express script to serve the files in the dist
folder. But then links like /dashboard
fails because there is no dashboard folder. So now I have to add a catch all endpoint that routes to index.html
file.
Suggested solution
Vite should just have a default script setting for running a full production app and optionally one more that route all other endpoint requests into index.html
file like this:
{
"start":"vite start",
"start-spa": "vite start-spa"
}
With of course ways to configure the port number in the vite config file.
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to Build A Single Page Application (SPA)
You can do exactly that by building single page applications, or SPAs, instead of traditional multi page websites (MPAs).
Read more >Pros and Cons of Building Single Page Applications in 2022
SPA is a web application taking a single HTML page. Delivering dynamic updates, it allows interacting with the page without refreshing it.
Read more >Single-page application - Wikipedia
A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with...
Read more >Choose between traditional web apps and single page apps
Learn how to choose between traditional web apps and single page applications (SPAs) when building web applications.
Read more >Angular SPA: Why Single Page Applications?
Single Page Applications are super easy to deploy in Production, and even to version over time! A single page application is super-simple to ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@TheInvoker oh, no,
npm run serve
does only 5% of static content serving ) It can’be used in production.That’s why you don’t use any npm for production and use nginx for example, letting vite focus only on crafting assets, but not serving them. And in fact, you should to use
npm run preview
to emulate static hosting, becausenpm run serve
works in development environment ) Serving static content is a much more complicated task then just “give me that image”, you can read more hereI agree with @the-illarionov too. Closing as this is expected.
I think we do at
https://github.com/vitejs/vite/blob/d76db0cae645beaecd970d95b4819158c5dd568a/packages/vite/src/node/preview.ts#L123