Skip to content

Commit 26400e4

Browse files
authored
fix: Read phoenix js assests at compile time (#355)
1 parent 6c50c60 commit 26400e4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

assets/js/app.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import "phoenix_html";
2-
import { Socket } from "phoenix";
31
import topbar from "../vendor/topbar";
4-
import { LiveSocket } from "phoenix_live_view";
52

63
let socketPath =
74
document.querySelector("html").getAttribute("phx-socket") || "/live";
@@ -228,7 +225,7 @@ let params = () => {
228225
};
229226
};
230227

231-
let liveSocket = new LiveSocket(socketPath, Socket, {
228+
let liveSocket = new LiveView.LiveSocket(socketPath, Phoenix.Socket, {
232229
params: params,
233230
hooks: Hooks,
234231
dom: {

lib/ash_admin/components/layouts.ex

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ defmodule AshAdmin.Layouts do
33
use AshAdmin.Web, :html
44
use Phoenix.Component
55

6-
js_path = Path.join(__DIR__, "../../../priv/static/assets/app.js")
7-
css_path = Path.join(__DIR__, "../../../priv/static/assets/app.css")
6+
phoenix_js_paths =
7+
for app <- ~w(phoenix phoenix_html phoenix_live_view)a do
8+
path = Application.app_dir(app, ["priv", "static", "#{app}.js"])
9+
Module.put_attribute(__MODULE__, :external_resource, path)
10+
path
11+
end
12+
13+
@static_path Application.app_dir(:ash_admin, ["priv", "static"])
814

9-
@external_resource js_path
10-
@external_resource css_path
15+
@external_resource js_path = Path.join(@static_path, "assets/app.js")
16+
@external_resource css_path = Path.join(@static_path, "assets/app.css")
1117

12-
@app_js File.read!(js_path)
18+
@app_js """
19+
#{for path <- phoenix_js_paths, do: path |> File.read!() |> String.replace("//# sourceMappingURL=", "// ")}
20+
#{File.read!(js_path)}
21+
"""
1322
@app_css File.read!(css_path)
1423

1524
def render("app.js", _), do: @app_js

0 commit comments

Comments
 (0)