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:

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.

Where Next?

Popular in RFCs Top

dergraf
Hey everyone! :waving_hand: I’ve been working on a side project for the last 4 months that I’m excited to share—it’s called ProxyConf! P...
New
bortzmeyer
Not a replacement for serious authoritative DNS servers, of course, but useful for some uses (such as returning the IP address of the DNS...
New
bluzky
Hi everyone, I would like to introduce my new project OrangeCMS, it’s an application that help you to create/edit content post for your ...
New
Billzabob
Hello! I have an idea for an Elixir library I’d like to work on, but wanted to get some thoughts from the community first. It would allo...
New
brettbeatty
At my work we build a lot of mix tasks for backfills and other maintenance tasks. Even with OptionParser we seem to copy a lot of boilerp...
New
manuel-rubio
There was some time when I started thinking about giving a boost to Lambdapad, the initiative from @garretsmith in Erlang that I loved wa...
New
KristerV
How I currently use Hexdocs I use hexdocs all day every day, but finding the right module and function takes too long even with my bookma...
New
zachallaun
Note: There are a few folks I’d really love to hear from, time permitting. Pinging in case the title isn’t catchy enough :slight_smile: @...
New
KristerV
I got fed up with removing unused aliases manually so made a package for it: GitHub - KristerV/remove_unused_ex: Remove unused aliases an...
New
benlime
In the last couple of days I was playing around with LiveView, function components and animations. I ended up with a little prototype whi...
New

Other popular topics Top

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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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

We're in Beta

About us Mission Statement