AndyL
JS/CSS Assets in Phoenix Library?
I’m working on a Phoenix library and it would be handy to inject custom CSS/JS assets into the parent app. In particular, I’d like to add a few window.addEventListeners to the parent app.js. Not sure how to do this & have not been able to find any examples or documentation. Is this possible, or should I fall back to manual install instructions in the README? Any links/tips/ideas appreciated.
Marked As Solved
al2o3cr
The default esbuild configuration adds the entire deps directory as an additional source of Node modules:
So users can load your package with import "your_package_name" if there’s a package.json at the root level; for instance, look at phoenix_html.
Also Liked
evadne
Best is not to do this as any way you do it would pollute global state. Instead, expose something that the developer can call to initialise.
benlime
I recommended this in a similar thread some time ago. You should add expose functions and provide clear instructions how to add custom JS from your library.







