SvelteKit without SSR / SSG? #3365
-
Describe the problemThere are several great things about SvelteKit; the power of Svelte, FS-based routing, __layouts, etc. All these goodies are affected by the extremely involved process required due to the fact that SvelteKit tries to support SSR / SSG. I do not care about SEO and search engines have learned to cope with dynamically generated layouts (or have to learn). I mostly care about all the power Svelte gives, and its design philosophy, plus the goodies that are added in SvelteKit. If SvelteKit had a way to provide all of that except SSR / SSG, I am sure we were enjoying 1.0 by now. I have struggled, for whole my weekend, to locally add Bootstrap's JS bundle to a simple SvelteKit project, and failed. Even with Describe the proposed solutionProvide a way to completely get rid of all the hassle of SSR / SSG for people that do not want / need it, and simplify their lives and at the same time, increase the number of people who fall in love with Svelte / SvelteKit. Something is missing somewhere between Svelte and SvelteKit. Alternatives consideredNo response Importancei cannot use SvelteKit without it Additional InformationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 22 replies
-
Add a export const ssr = false; This disables SSR for all pages and you can use libraries that only work in the browser without additional checks. See the docs for more details https://kit.svelte.dev/page-options#ssr For the adapter you can use
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
fallback: 'index.html',
}),
prerender: {
entries: [],
},
};
export default config; |
Beta Was this translation helpful? Give feedback.
-
Thanks @dummdidumm, I will try the solution. Two minor issues: This should be more visible, as many people may need it, and, it is so much better to have a minimal example somewhere, so people can base their work on. |
Beta Was this translation helpful? Give feedback.
-
Still the same issue: <script>
import 'bootstrap';
</script> In export const handle = async function handle({ request, resolve }) {
const response = await resolve(request, {
ssr: false
});
return response;
} In import adapter from "@sveltejs/adapter-static";
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
fallback: 'index.html',
}),
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
},
};
export default config; Now,
Any idea? |
Beta Was this translation helpful? Give feedback.
-
The following import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
fallback: 'index.html',
}),
prerender: {
enabled: false,
},
ssr: false,
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
},
};
export default config; I am not sure if Thanks @dummdidumm for helping out! |
Beta Was this translation helpful? Give feedback.
-
@dummdidumm I am getting this now when running
It seems that the locally served site works fine, though. Any idea? This is getting really annoying... |
Beta Was this translation helpful? Give feedback.
-
Hello, From the adapter-static github page:
This seems a bit vague to me and not sure how it would apply to SvelteKit specifically. In the Surge example it is simply showing the HTML file as being:
What would the SvelteKit equivalent be? Thanks! |
Beta Was this translation helpful? Give feedback.
-
This information is already obsolete? I followed this discussion and nothing worked :) IMHO not having a simple option to roll out html like vanila svelt has and decouple server from backend is the most sad thing about sveltkit as I won't be able to use it. And I bet there are others in the same situation as serverless is more and more used. |
Beta Was this translation helpful? Give feedback.
-
the prerender, ssr and target parameters are causing the npm run dev to produce an error:
Is this still up-to-date? If not, is there a way to hide this from search engine indexers? |
Beta Was this translation helpful? Give feedback.
-
After reading this thread's replies, I'm still puzzled by a few things:
Much thanks! |
Beta Was this translation helpful? Give feedback.
Add a
src/routes/+layout.js
file withThis disables SSR for all pages and you can use libraries that only work in the browser without additional checks. See the docs for more details https://kit.svelte.dev/page-options#ssr
For the adapter you can use
adapter-static
with SPA mode: https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-modesvelte.config.js
then looks something like this: