Rodolpho

Rodolpho

Svelte framework on Phoenix

Hi to all. I’m new to Elixir and Phoenix.

I’d like to use Svelte framework with Phoenix for a learning purpose project but I don’t know how to set things up.

Anyone here can help me with that, and maybe share how it’s like to use them together.

Thanks!

Most Liked

LostKobrakai

LostKobrakai

To get started you should just need to install the svelte + svelte loader in the webpack pipeline of phoenix. Then use the client side component api to put components into the server side rendered html.

Rodolpho

Rodolpho

I’d like to thank everyone here for the help.

I did the ajustments in Webpack following the demo provided and the template from Svelte (template-webpack/webpack.config.js at master · sveltejs/template-webpack · GitHub), which also set things like:

module.exports = {
	(...)
	resolve: {
		extensions: ['.mjs', '.js', '.svelte']

I’ve bumped into an error (Runtime Error “require is not defined”) in the browser that prevented requires() injection into the index.mjs file.
I was able to get things working by the solution provided in https://stackoverflow.com/questions/52366829/require-is-not-defined-using-webpack-and-yarn, which consists in including a especific rule for .mjs in the webpack.config.js like:

{
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto",
      },

If anyone could share some design patterns tips on how to best integrate phoenix templates with Svelte components I would greatly appreciate.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New