sezaru

sezaru

Consider this scenario: I’m creating a library that contains a phoenix component on it. That component requires a hook, and that hook imports some JS library to do its job.

What is the correct approach to make my Phoenix project (or esbuild for that matter), that has my library as a dependency, see that JS library correctly (let’s say the JS library is in deps/my_library/assets/node_modules/library)?

Esbuild will obviously find the path for the Phoenix project node_modules in assets/node_modules via the :cd in config, but it doesn’t know about my library path at all.

I guess I could generate a dist directory with the hooks + JS libraries already bundled with esbuild and push it to the library repo, but I’m not sure if that would be the best approach to solve this or if there is some corner cases.

Marked As Solved

D4no0

D4no0

I’m not positive 100% on a correct approach, however I think you can use the approach liveview uses to serve the JS it requires to be up and running.

The way it does is by placing the JS files in priv folder.

Then you import them in your own project and you can use them directly from js.

Also Liked

LostKobrakai

LostKobrakai

Yeah, essentially you can make your mix project an npm project as well. You can then have your user lookup deps as a possible node_modules folder. That’s what phoenix does with it’s own project internal dependencies as well.

sezaru

sezaru OP

Thank you, that did it, I replicated the way liveview does for their JS stuff and it worked like a charm. I also added a package.json file to the root of the project like @LostKobrakai mentioned and now I can import the library the same way we do with lv (import {LiveSocket} from "phoenix_live_view") pretty neat!

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews