LostKobrakai

LostKobrakai

PhoenixVite - Integrating the vite built tooling with phoenix

I’ve recently created a small library phoenix_vite integrating the vite build tooling with phoenix.

It

  • provides an igniter.installer to install all the necessary files
    • creates elixir and js boilerplate
    • configures phoenix LV static file tracking with the manifest vite generates
    • uses phoenix static_url configuration to handle all static assets via the vite dev server
    • moves static assets from priv/static to assets/public
  • provides a heex function component to pull in js/css from
    • vite dev server in development
    • the vite manifest in prod
  • can optionally pull in :bun to run without a locally installed nodejs, just like phoenix does by default

When used with :bun this should provide a setup that’s as “working out of the box” as the default phoenix boilerplate, but including package managing as well as an very flexible and extensible build system.

The installer could likely use a bit more work around the failure cases, but it works for fresh phoenix 1.7/1.8 projects.

You can install the package by adding it to your mix.exs and running

mix phoenix_vite.install [--bun]

or all in one using

mix igniter.install phoenix_vite [--bun]

or from scratch

mix igniter.new my_app --with phx.new --install phoenix_vite [--bun]

https://github.com/LostKobrakai/phoenix_vite

Most Liked

LostKobrakai

LostKobrakai

I just published 0.4.0. The major themes of the updates have been

  • properly supporting nodejs (no zombie processes)
  • integrating with phoenix_live_reloads :notify feature
  • some optimizations to the generated vite config
  • support the release version of phoenix 1.8.0 and 1.8.1
  • fixing things up generally
Jskalc

Jskalc

Thank you for this @LostKobrakai!

LiveVue relies heavily on Vite, but installation instructions are long and discourage trying it out (even 3min setup is too much for many :joy:).

I started working on Igniter installer but didn’t had the time to finish. Your library seems like a solid foundation to build upon. I will give it a shot later this week and hopefully I could include phoenix_vite in the next version!

Two questions:

  1. When working on my installation process I’ve stumbled upon a problem with Vite configured to do chunk splitting. Eg:
defineAsyncComponent(() => import('@assets/vue/components/MarkdownBlock.vue'))

might create a separate chunk. Then, code of that chunk will try to import shared parts from app.ts, because these chunks doesn’t know about phoenix manifest. So we’ll end up with two app.ts files loaded, one hashed by phoenix and one not.

My solution was not to use phoenix manifest file, instead use vite hashing. It was also important when generating preload directives for SSR, since when doing SSR with Vite it’s using chunk names from vite manifest.

I’m pretty sure some interoperability can be reached between these two manifests - adjusting one manifest to use file names from the other one. But it felt like a rabbit hole at a time.

  1. LiveVue extends vite dev server to also do efficient SSR during development, and handle some corner cases about hot updates (if I recall, it was about css and js). Do you think it would make sense to add it to your library?
LostKobrakai

LostKobrakai

This does the same. The vite manifest is the source of truth and is used to provide information to phoenix. phx.digest is not used.

ravecat

ravecat

@LostKobrakai thanks for the great work! thanks to your project, I will finally be able to transfer Phoenix + Inertia projects to vite. I’ll leave an example in repository for the future. SSR is still a work in progress, but I’m quite happy with the current result

te_chris

te_chris

Interesting. I ended up DIYing alongside our over-eager AI friends. Works really well and, with inertia, means we can rapidly vibe code our admin.

Where Next?

Popular in Announcing Top

zachdaniel
Hey folks! AshEvents Release We’ve just released the first version of AshEvents, an Event Sourcing tool for Ash Framework apps. Check o...
New
metehan
exterm_ai runs a real PTY in Elixir and exposes it in the browser using xterm.js. Previously I shared exterm library without AI this one ...
#ai
New
fuelen
Hi all! Confispex is a tool which allows defining specs for runtime configuration, cast values according to specified types and inspect ...
New
jechol
I’m excited to share FeistelCipher and AshFeistelCipher, PostgreSQL-based libraries that provide encrypted integer IDs using the Feistel ...
New
munksgaard
flakify is an igniter installer that allows you to quickly get a Nix flake-based development shell up and running for your Elixir/Phoenix...
New
murrgelb
Efx is a library to define and test side effects declaratively. It is basically a very focused mocking framework, reducing implementation...
New
fhunleth
Elixir Circuits is a set of libraries for interacting with hardware. We previously announced Circuits.UART, and now we’re ready to announ...
New
mattmower
I’m pleased to announce that we’ve released DemoGen v0.1.7, a library for creating repeatable demo scenarios in your Ecto-based SaaS appl...
New
sevensidedmarble
Announcing Live Toast: a replacement toast/flash component for Phoenix LiveView, heavily inspired by the look of Sonner (the amazing toas...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
194 10054 106
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement