-
Hello! First off, thanks for such a cool library. I love svelte, and learning Phoenix with svelte so far is an awesome experience. Am I missing something here, or is this just a limitation of combing phoenix with svelte? Is there a way to only send the components when the user navigates to a specific live_view and/or page? Thanks again for creating such a cool hybrid of a framework. Any info would be greatly appreciated : ) Liam. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Hi @Mali-2 thanks for the interest :) At the moment all Svelte files are included inside the singular js bundle that's being generated. By default, Phoenix with Esbuild doesn't do code splitting. It just includes one big js bundle. Sveltekit does use code splitting which is what you're referring to I believe. The entrypoint for the bundle in Phoenix is the import * as SvelteComponents from "../svelte/**/*" This dynamically includes all Svelte files in the I'm not sure how hard it is to add code splitting to a phoenix project with Esbuild. From the documentation it seems esbuild doesn't really support it fully. An alternative would be to use Vite with Phoenix and use route based code splitting but hooking that up with Phoenix routes... seems pretty hard. So it's indeed a limitation of combining phoenix with Svelte. An alternative approach you could take is manually generating multiple js bundles with esbuild, and then manually including those bundles on specific pages. This will take some time and manual effort though. Maybe also look into this: https://elixirforum.com/t/page-specific-javascript-with-liveview-and-esbuild-phoenix-1-6-0/42359/12 This topic looks pretty hairy though |
Beta Was this translation helpful? Give feedback.
-
@NotM32 Curious, did you ever get a chance to publish? Very interested in taking a look. |
Beta Was this translation helpful? Give feedback.
Hi @Mali-2 thanks for the interest :)
At the moment all Svelte files are included inside the singular js bundle that's being generated. By default, Phoenix with Esbuild doesn't do code splitting. It just includes one big js bundle. Sveltekit does use code splitting which is what you're referring to I believe. The entrypoint for the bundle in Phoenix is the
app.js
file and you'll notice the line:This dynamically includes all Svelte files in the
svelte/
directory.I'm not sure how hard it is to add code splitting to a phoenix project with Esbuild. From the documentation it seems esbuild doesn't really support it fully. An alternative would…