dkuku
I Created a blog post about setting up svelte with phoenix.
I found it a bit tricky and the only blog post I found was written using some strange alphabet on medium.
with this setup you can add svelte components to templates with just:
<%= svelte "test", %{:name => "svelte"} %>
At the end I also attached links to gists with diffs against the app - may be helpful. I hope it helps someone.
https://dkuku.github.io/phoenix-svelte-setup
Trending in Guides/Tuts
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sergiobrr
Hi dkuku, thanks a lot for the amazing solution to integrate svelte into phoenix!
I’m new in both frameworks, so i ask you an opinion about the best approach to have, i mean, the best way to use svelte into phoenix is to use it in a widget style letting phoenix manage routing and using it’s templates, or mounting a single page svelte app in layout.html and use phoenix just as an api serving backend?
Sergio
dkuku
Hi Sergio. This setup is more for small widgets - if you want a true single page app I suggest you to choose a separate backend and frontend repo. Here after the data changes the page gets reloaded. Also you will find more tutorials similiar to your setup when you split the backend and frontend.
silverdr
@dkuku - thank you for the post there. After trying to follow this one:
I followed yours, which I find “better” (use your definition of this word
I ran however into a problem of:
once I
import './svelte.js';Is this something you’ve seen and solved? Any hints?
im3000
Without seeing the actual code, did you put that import statement at the top of the
app.jsfile together with the rest of the imports? This is what the message says anyway.silverdr
That’s the whole app.js. I appended the import but I don’t think the “top level” means “top of the file” here, does it?
silverdr
Webpack config, which I supect is the culprit here looks as follows:
im3000
Hard to say what it can be. Looks right, but JS is very fragile. Can you share the actual JS stack trace? Or maybe try this one? GitHub - virkillz/sveltex: Elixir Phoenix + Svelte = ❤️ · GitHub
silverdr
Here it comes:
hello.svelteis the helloworld type of:im3000
Hmm .. Hard to say what it can be. It’s obviously that it’s something in the Webpack config. Are you passing in name as a property to the Svelte component? If yes, then you forgot to prefix
let namewith export, likeexport let name =, but I don’t think that should matter. It’s probably something else.silverdr
Found the culprit: Error in release 3.1.1 (Module parse failed: 'import' and 'export' may only appear at the top level (138:339)) · Issue #178 · sveltejs/svelte-loader · GitHub