3

Is there an option to let Elm know which module system you're targeting during compile time? E.g. something like a --target flag. I must admit that I haven't dug into elm-make that much.

Currently it seems that it only occurs during runtime:


For my situation I'm:

  • Using Electron which defines it's own module object and a global window.
  • Only using Elm for a portion of the project (See HTML interop).

By default, the compiled output defaults to exposing Elm on module.exports:

if (typeof define === "function" && define['amd'])
{
  define([], function() { return Elm; });
  return;
}

if (typeof module === "object")
{
  module['exports'] = Elm;
  return;
}

var globalElm = this['Elm'];
if (typeof globalElm === "undefined")
{
  this['Elm'] = Elm;
  return;
}

In debug tools:

TronWM exposed in module.exports vs window

Instead, I want it to expose it on this/window and not overwrite module.exports with the Elm object.

I was able to hack together a solution that abuses the AMD check:

    <script>
    window.define = (arr, fn) => {
        const Elm = fn();
        window.Elm = Elm;
    };
    window.define.amd = true;
    </script>
    <script src="build/tronwm.js"></script>
    <script>
    const node = document.getElementById('elm-render');
    const app = window.Elm.TronWM.embed(node);
    </script>

enter image description here


This works for now, but curious of alternate solutions if any.

Jay
  • 18,959
  • 11
  • 53
  • 72

1 Answers1

1

As of 0.18, no there is not. The Elm compiler does not know about details of JS Loaders etc.

Zachary K
  • 3,205
  • 1
  • 29
  • 36