Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julius script type module support #1681

Open
jmorag opened this issue Jun 21, 2020 · 3 comments
Open

Julius script type module support #1681

jmorag opened this issue Jun 21, 2020 · 3 comments

Comments

@jmorag
Copy link

jmorag commented Jun 21, 2020

Is there a way for julius files to be emitted with <script type="module"> tags? As far as I can tell from these instances:

instance render ~ RY site => ToWidgetHead site (render -> Javascript) where
    toWidgetHead j = toWidgetHead $ \r -> H.script $ preEscapedLazyText $ renderJavascriptUrl r j
instance ToWidgetHead site Javascript where
    toWidgetHead j = toWidgetHead $ \_ -> H.script $ preEscapedLazyText $ renderJavascript j

it isn't possible without defining a newtype over Javascript or something. In any case, it would be nice to be able to use something like preact/htm with variable interpolation this way. I can attempt a PR to add jsModule/juliusModule/jsFileModule/etc. quasiquoters but I figured I'd gauge interest and feasibility here before going ahead with that.

@snoyberg
Copy link
Member

Currently you'd have to do some legwork involving rendering the Julius to text and then embedding it inside a Hamlet tag. I'm definitely open to a PR to add some direct support for this workflow.

@JohnnyCrazy
Copy link

JohnnyCrazy commented Aug 31, 2020

Is there any workaround for supporting javascript modules at the moment?

I have a simple games.mjs in my static/js folder and loading it via the below code obviously fails because of the missing type=module attribute.

defaultLayout $ do
  addScript (StaticR js_games_mjs)
  $(widgetFile "games")

EDIT

A rather hacky solution is to include it on the bottom of the games.hamlet widget file, but works for me for now:

<script type="module" src=@{StaticR js_games_mjs}>

@jmorag
Copy link
Author

jmorag commented Aug 31, 2020

@JohnnyCrazy If you don't need any interpolation in your module file, then your workaround is a good idea. I've started working on a version using interpolation here: #1682, but I've run into some issues testing it. I've not had time to work on it in a few weeks but hopefully I can get back to it soon and clean it up so it can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants