gilest

gilest

Phoenix Importmap - Alternative to esbuild

Hi all

Relatively new to Elixir, but was curious to see how Phoenix might run with a basic importmap configuration.

Introducing, phoenix_importmap.

Benefits:
In dev - minimal file-based tooling, removal of esbuild transpilation step, parity with prod
In prod - more granular caching of js files since they are many rather than a few bundles

Curious to know if folks are interested in this approach, anyway.

Usual disclaimer - this is an early stage library. I’ve not yet used it in prod :slightly_smiling_face:

https://github.com/gilest/phoenix_importmap

Most Liked

derek-zhou

derek-zhou

Neat. I am using a more bare bone nobuild setup. I made sym links of phoenix js into my static dir:

derek@roastidious:~/projects/gara$ ls -al priv/static/js/
total 36
drwxr-xr-x 3 derek derek 4096 Mar  3 16:20  .
drwxr-xr-x 7 derek derek 4096 Oct 12 15:00  ..
-rw-r--r-- 1 derek derek 2160 Oct 12 15:08  app.js
drwxr-xr-x 2 derek derek 4096 Apr  8  2023  _hooks
lrwxrwxrwx 1 derek derek   54 Oct 12 14:49  phoenix_html.js -> ../../../deps/phoenix_html/priv/static/phoenix_html.js
lrwxrwxrwx 1 derek derek   45 Oct 12 14:51  phoenix.js -> ../../../deps/phoenix/priv/static/phoenix.mjs
lrwxrwxrwx 1 derek derek   68 Oct 12 14:52  phoenix_live_view.js -> ../../../deps/phoenix_live_view/priv/static/phoenix_live_view.esm.js

Then I directly import those phoenix js in my app.js:

import "./phoenix_html.js";
import {Socket} from "./phoenix.js";
import {LiveSocket} from "./phoenix_live_view.js";
import Hooks from "./_hooks/index.js";

If I need to use more than a couple of npm modules, I will consider using the importmap package.

jakeprem

jakeprem

This is really interesting thanks for making it!

I’ll have to take a closer look next time I venture outside the LiveView bubble.

Last Post!

derek-zhou

derek-zhou

I don’t copy assets from assets/ to priv/ any more. My original js and css lives directly under priv/static/ and the phoenix js are symlink’ed to priv/static/js/ and remain that way in the release. The symlinks are flatten in deploy.

Where Next?

Popular in RFCs Top

pzingg
https://github.com/pzingg/phx_cookie_consent I took a phx.gen.auth application and added support for storing a user’s cookie consent set...
New
senconscious
EctoJuno is a package that provides parsing, validation and applying sorting parameters for your ecto queries on models. Currently sortin...
New
pepicrft
Hey folks :wave: I implemented a library that uses macros extensively, and I’d appreciate feedback from people that are more versed at w...
New
blubparadox
Hi all. If you’ve looked on Twitter or YouTube you’ve seen the 1 billion row challenge, usually done in Java. I’ve written an Elixir vers...
New
dimamik
Hi! I’ve been working with Pipecat in Python for quite a while now, and while it’s effortless to set up, when building AI voice agents at...
New
andreashasse
Hi all, I’ve been working on PhoenixSpectral, a library that makes Phoenix controller @spec annotations drive both OpenAPI generation an...
New
bartblast
:test_tube: Could use a hand testing something. Just landed a protocol pruning enhancement - the compiler now drops protocol implementati...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
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
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement