Hi all,
The process of creating a Hex package is good documented and quite straight, but what if I have an extension to Phoenix which contains not only the server-side lib, but also some static content (javascripts, images)? What is the best approach do deliver such package? Install the hex and after it call some mix task like “mix my_package.install”, which copies some files into vendor/ ?
One of implementation could be - adding plug dependency to the mix file of the project. then configure it
And after making configure to make it work with plug.
Then you add that package as the mix dependency and then you configure your phoenix app to use that plug in the phoenix endpoint.
There is an example below of how phoenix use static plug - (location: lib/endpoint.ex)
plug Plug.Static,
at: “/”, from: :stock, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
We could do similar way to solve your problem.
The implementation might be little difficult, but I think that this should answer your question.
–
Dev
After looking into your Problem again last night. I want to update my answer little more. I don’t think we need plug as dependency in another app also.
Since I think we could do something like this -. Let’s consider your another app (The app that you want to put to the hex and then add this app as your dependency to the Phoenix app) has your static files under
priv/static path. You could create a plug like below that will get static assets from your hex package.
plug Plug.Static,
at “/fromhex/”, from: :youhexpackagename, gzip: false
Please try. I think this should work
–
Dev.
Hi Dev,
Thanks for the idea! I might give it a try, but actually looks like my issue is how to provide the javascript library only. No need to put any other static files. So the easiest would be to create the npm
package in the hex library and call it as a depepndecy - exactly like it is done for Phoenix javascript ("phoenix": "file:deps/phoenix"
).
Anyway, thanks a lot.
Got any links for documentation pertaining to creating a hex package - I’d like to create a task which I’d release open-source.