DaAnalyst

DaAnalyst

Yesterday I encountered the following problem for the first time:

Having a dependency on a library that has its JS script modules colocated with the corresponding LiveComponent templates correctly results in having the JS class(es) end up in the library subdirectory within the phoenix-colocated directory, but no manifest file(s) are generated so I wonder how to import those classes and make thus imported web components visible to the app.

Shouldn’t there be support for this?

Showing Posts 1 to 6

frankdugan3

frankdugan3

They are namespaced by the application, so you just need to add another entry to your hooks:

import { hooks as yourLibHooks } from 'phoenix-colocated/your_lib'
  hooks: {...colocatedHooks, ...yourLibHooks}
DaAnalyst

DaAnalyst OP

Nope. I’ve already tried that. I’m getting ✘ [ERROR] Could not resolve "phoenix-colocated/mylib"
although the library’s live component’s folder is in that directory and the generated .js file in it.
No manifest file though - which is what seems to be the problem.

btw, I’m not using hooks. those are custom elements.

mortenlund

mortenlund

I do this by adding the library to the ESBuild config.
Something like this (See NODE_PATH):

config :esbuild,
  version: "0.25.4",
  default: [
    args: ~w(js/app.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.),
    cd: Path.expand("../assets", __DIR__),
    env: %{
      "NODE_PATH" => [
        Path.expand("../deps", __DIR__),
        "#{Mix.Project.deps_paths()[:mylib]}/assets/node_modules",
        Mix.Project.build_path()
      ]
    }
  ]
DaAnalyst

DaAnalyst OP

So you add node_modules to the NODE_PATH, but how does this help the JS import statement see the JS files?

My path is already visible to the bundler because the part with generating the temporary JS (from the library’s JS in its own assets/js) and putting it in the app’s ../phoenix_colocated/mylib subfolder is already being done correctly by Phoenix, but the bundler doesn’t know what to do with it because there’s no automatically generated “index.js” manifest file for it.

It could be I’m missing something or doing something wrong or that the library should be doing something it doesn’t in its build process, the issue is the app has the automatically generated manifest files for all of its own colocated web components but not for the library’s.

steffend

steffend

Phoenix Core Team

@DaAnalyst does your library properly set

compilers: [:phoenix_live_view] ++ Mix.compilers(),

in your mix.exs?

DaAnalyst

DaAnalyst OP

No, it doesn’t. Will try that. Thanks a lot!

— All posts loaded —

Where Next? Top

Trending in Proposals: Ideas Top

woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews