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.

Where Next?

Popular in Announcing Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps w...
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement