Skip to content

Commit

Permalink
Allow configuring script type
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Schmatzler <[email protected]>
  • Loading branch information
cschmatzler authored and cblavier committed Jan 17, 2025
1 parent 9813d0d commit ef3e480
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions guides/sandboxing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Then set the `js_path: "/assets/storybook.js"` option to the storybook within yo
file. This is a remote path (not a local file-system path) which means this file should be served
by your own application endpoint with the given path.

If you are using ESM-style imports, you can set the `js_script_type: "module"`" option as well.

You can also use this script to inject whatever content you want into document `HEAD`, such as
external scripts.

Expand Down
4 changes: 3 additions & 1 deletion lib/phoenix_storybook/templates/layout/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
<script
nonce={csp_nonce(@conn, :script)}
phx-track-static
type="text/javascript"
defer={storybook_js_type(@conn) == "module"}
type={storybook_js_type(@conn)}
src={application_static_path(path)}
>
</script>
<% end %>
<script
nonce={csp_nonce(@conn, :script)}
defer={storybook_js_type(@conn) == "module"}
type="text/javascript"
src={asset_path(@conn, "js/app.js")}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script
nonce={csp_nonce(@conn, :script)}
phx-track-static
type="text/javascript"
type={storybook_js_type(@conn)}
src={application_static_path(path)}
>
</script>
Expand Down
1 change: 1 addition & 0 deletions lib/phoenix_storybook/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ defmodule PhoenixStorybook.LayoutView do

def storybook_css_path(conn), do: storybook_setting(conn, :css_path)
def storybook_js_path(conn), do: storybook_setting(conn, :js_path)
def storybook_js_type(conn), do: storybook_setting(conn, :js_script_type, "text/javascript")

defp title(conn_or_socket), do: storybook_setting(conn_or_socket, :title, "Live Storybook")

Expand Down

0 comments on commit ef3e480

Please sign in to comment.