Hello,
I’d like to try out Elm in an existing app (a rails app) by integrating “widgets” as described here: JavaScript Interop · An Introduction to Elm
I’m a little unsure of my strategy so I’m submitting this for feedback.
This is how I plan to do load the code (for any page integrating a “widget”)
<!-- A server will render this HTML -->
<h3>A counter</h3>
<div id="elm-counter"></div>
<!-- Below generates a script tag pointing to a compiled elm module -->
<%= javascript_include_tag 'elm/dist/Counter.js' %>
<script defer>
Elm.Counter.init({
node: document.getElementById('elm-counter')
});
</script>
<h3>Rest of the page goes here</h3>
To make the Elm.ModuleName.init
workflow possible, I compile my Elm files with a script similar to this:
find ./src/*.elm | xargs -IFILE elm make FILE --optimize --output ./dist/FILE.js
However, I then get 100k files for each module.
> find ./dist/ | xargs -n1 du -sh
200K ./dist/
108K ./dist/Counter.js
88K ./dist/Widget.js
Here, Counter.js
and Widget.js
share mostly the same code, 99% of the file size is duplication from elm make
Is there a smarter way to proceed here with this workflow?
I suppose one would want to load the least amount of modules this way to prevent bloat, preferably one?