woohaaha

woohaaha

Setting up Vite with Phoenix

I’d like to use Vite with Phoenix on a new project and have run into questions that I haven’t seen discussed.

  1. When starting up, are ya’ll running npx create-vite . in the ./assets directory? If yes, are you removing everything else in the directory?
  2. Are you running the Vite dev server alongside the Phoenix server?
  3. How are you handling both custom css and tailwindcss?
  4. I’ve noticed the following code example and am wondering why 3000 is specified since that is neither Vite’s or Phoenix’s default port.
<%= if dev?() do %>
  <script type="module" src="http://localhost:3000/@vite/client"></script>
  <script type="module" src="http://localhost:3000/js/app.js"></script>
<% else %>
  <link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
  <script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
<% end %>

Maybe I should be asking if anyone has the series of steps to setup Vite with Phoenix in 2024? :thinking:

Thanks all :slight_smile:

Most Liked

LostKobrakai

LostKobrakai

The default used to be 3000 around V2. But the half-life period in the js ecosystem is so short, that stuff becomes outdated by the hour it seems.

c4710n

c4710n

Hey, @woohaaha. I have a repo for this - GitHub - dodrio/phoenix_custom_assets: Provides an alternative assets/ of Phoenix for using LiveView and TailwindCSS. · GitHub.

It’s quite a coincidence; I just marked this repository as archived yesterday because I found a simpler method - https://forum.elixirforum.com/t/phoenix-and-the-asset-pipeline/60736/3.

But, you can still follow the repo, it has detailed instructions on how to setup.


Edit: Sorry for replying wrong people.

mike1o1

mike1o1

I’ve recently setup a similar stack. I found these guide to be extremely helpful and kind of picked and chose between both similar approaches.

Basically, I set things up in frontend folder, but could also have been in the assets folder too. I run Vite in a separate process (using the mix watchers) on port 3000, with Vite dev server producing requests to port 4000 where phoenix is running. 90% of the time I access the app on port 3000 (Vite) during development.

I also have the Vite production build copy directly to the phoenix assets directory and can easily do a build and access the full app on port 4000 at any time. I have a catch all controller that serves up the dist index.html file.

I’m very comfortable with React and the tool chains and find myself very productive, though phoenix is really just acting as an API server for now.

Last Post!

bmazaheri

bmazaheri

Maybe this post can answer some of the questions:

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
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement