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

Building separate JS files #14

Open
dpinn opened this issue Aug 22, 2017 · 1 comment
Open

Building separate JS files #14

dpinn opened this issue Aug 22, 2017 · 1 comment

Comments

@dpinn
Copy link

dpinn commented Aug 22, 2017

My Play Framework app delivers a number of separate HTML pages to the browser. Rather than download elmMain.js into each of those pages, I would prefer each HTML page to download only the Elm-generated JavaScript that it needs. For example, my ConfigPage.html wants to embed elmConfigPage.js; and my ProjectAdmin.html wants to embed elmProjectAdmin.js.

Can you imagine how I might be able to achieve that with sbt-elm?
Would it require a very significant change to sbt-elm?

@krzemin
Copy link

krzemin commented Oct 6, 2018

If all of your sources are under single elm project (elm-package.json or elm.json), it's relatively easy to do so.

lazy val `frontend-app1` = project.in(file(".elm/app1"))
  .enablePlugins(SbtWeb, SbtElm)
  .settings(
    name := "frontend-app1",
    inConfig(Assets)(Seq(
      sourceDirectories in elmMake := Seq(new File("elm/App1")),
      elmOutput in elmMake := (resourceManaged in elmMake).value / "js" / "App1.js"
    )),
    (managedClasspath in Runtime) += (packageBin in Assets).value,
    publishArtifact in (Compile, packageDoc) := false,
    publishArtifact in packageDoc := false,
    sources in (Compile,doc) := Seq.empty
  )

lazy val `frontend-app2` = project.in(file(".elm/app2"))
  .enablePlugins(SbtWeb, SbtElm)
  .settings(
    name := "frontend-app2",
    inConfig(Assets)(Seq(
      sourceDirectories in elmMake := Seq(new File("elm/App2")),
      elmOutput in elmMake := (resourceManaged in elmMake).value / "js" / "App2.js"
    )),
    (managedClasspath in Runtime) += (packageBin in Assets).value,
    publishArtifact in (Compile, packageDoc) := false,
    publishArtifact in packageDoc := false,
    sources in (Compile,doc) := Seq.empty
  )

Idea is to keep elm.json (elm-package.json in case of 0.18) in root directory, sources in elm/ directory, but also have all AppX application sources (including Main module) contained in elm/AppX directory.

It's a bit worse, when you have multiple, independent elm projects (separate elm-package.jsons) as it seems sbt-web doesn't support such case.

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

2 participants