Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simplify configuration for SPA applications #94

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

jkirkpatrick24
Copy link

The initial implementation for SPAs required some unnecessary files to be created when running production build: This pull request removes the requirement for a build:server step and the existence of an ssr manifest when spa mode is set to true. This also adds a react-vanilla-spa example to show users how to configure this mode.

Checklist

The initial implementation for SPAs required some unnecessary files to be created when running
production build: This pull request removes the requirement for a build:server step and the
existance of an ssr manifest when spa mode is set to `true`. This also adds a react-vanilla-spa
example to show users how to configure this mode.
@jkirkpatrick24
Copy link
Author

Hey @galvez,

Thanks again for your time responding to #92. I dug a little deeper into the implementation and it looks to me like there were some unnecessary steps required to get SPA mode working in production. I removed the check for the SSR manifest as well as the /dist/server bundle when spa mode is enabled. I also included a new example of spa mode in a vanilla react application.

If you think this all makes sense I can update the docs as well to explain the setup a bit more.

Cheers!

const bundle = {}
if (!dev) {
bundle.dir = resolve(vite.root, vite.build.outDir)
const indexHtmlPath = resolve(bundle.dir, 'client/index.html')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this as /dist/client, but it may make sense to remove this hard dependency on having a /client folder. SPAs should probably just use the /dist output (or at least allow for configuration)

Any thoughts on that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSYK There's no hard dependency on having a client/ folder, root in vite.config.js can be the same folder as server.js and it should work fine.

Amazing work, I'll give it a go and review properly soon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok cool thanks!

What I meant here was that AFAICT, the output folder has to be /client right now for production. Unless there is a way of overriding how the production bundles are loaded that I missed.

@galvez
Copy link
Member

galvez commented Jan 3, 2023

I'm merging this PR as-is but I'm making the tweak on removing the /client folder and just using top-level /dist for SPA builds separately in dev. Thanks again for the amazing contribution!

@galvez galvez merged commit 01bf52f into fastify:dev Jan 3, 2023
@jkirkpatrick24
Copy link
Author

@galvez thanks for reviewing! My pleasure, I’m glad it’s a useful contribution to the project 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants