fbonetti / elm-rails

View helpers for incorporating Elm modules into Rails views
MIT License
75 stars 20 forks source link

requiring modules in different directories under assets/elm? #21

Closed 97jaz closed 7 years ago

97jaz commented 7 years ago

I'm probably doing something wrong, but I can't get elm-make to find all of my modules when going through the asset pipeline. (It works in a repl, so I'm not sure what's going one.)

I have a directory structure like:

app/assets/elm
app/assets/elm/Models
app/assets/elm/Api

where my main module (in app/assets/elm) imports modules from the other directories, and modules in Models also depend on a module in Api. I added require lines to my app/assets/javascripts/application.js, but when elm-make tries to compile a module in Models that depends on one in Api, it can't find it.

Originally my elm-package.json (in the root of the rails project) just had "." in source-directories, so I tried adding "Api" and "Models," but that didn't help.

97jaz commented 7 years ago

Come to think of it, the require lines in application.js are probably a red herring, right? I don't really need the asset pipeline to find these files, just the elm compiler.

97jaz commented 7 years ago

Ok, I found the issue. I figured that since source-directories in elm-package.json is ["."], that meant that the compiler was being run with a cwd of app/assets/elm, but that's not the case. It's run from the project root with input paths like: app/assets/elm/.... So I needed to add paths like "app/assets/elm/Api" to source-directories (instead of paths like "Api"). Anyhow, I got it to work. A note in the readme about that would probably be a good idea.