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
You probably already know that <span>{nil}</span> in a HEEX template produces <span> </span> when rendered. I fin...
New
Other Trending Topics
Hey! At Software Mansion we’ve just released Legion, a library that puts AI agents inside your Elixir app, and we’d love to hear what you...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










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