question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to run a real production app and support for SPA

See original GitHub issue

Description

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

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
the-illarionovcommented, Nov 18, 2022

@TheInvoker oh, no, npm run serve does only 5% of static content serving ) It can’be used in production.

  1. No cache handling.
  2. No proxy.
  3. No redirects.
  4. No firewall
  5. And lots of other network-engineering kitchen.

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, because npm 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 here

0reactions
bluwycommented, Nov 28, 2022

I agree with @the-illarionov too. Closing as this is expected.

I feel like they should just have another thing to complete the remaining 20% (i.e. serve it for prod with spa re-routing).

I think we do at

https://github.com/vitejs/vite/blob/d76db0cae645beaecd970d95b4819158c5dd568a/packages/vite/src/node/preview.ts#L123

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found