I did a checkout of the scala.js example project and modified it a little bit.
First, edit index.html
and replace the following lines:
<script type="text/javascript" src="./target/scala-2.11/example-opt.js"></script>
<script type="text/javascript" src="./target/scala-2.11/example-launcher.js"></script>
with:
<script type="text/javascript" src="{{example.js}}"></script>
<script type="text/javascript" src="example-launcher.js"></script>
Next, add the following lines in build.sbt:
def generateIndexTask(suffix: String) = Def.task {
val source = baseDirectory.value / "index.html"
val target = (crossTarget in Compile).value / "index.html"
val log = streams.value.log
IO.writeLines(target,
IO.readLines(source).map {
line => line.replace("{{example.js}}", s"example-$suffix.js")
}
)
log.info(s"generate with suffix: $suffix")
}
(fastOptJS in Compile) <<= (fastOptJS in Compile).dependsOn(generateIndexTask("fastopt"))
(fullOptJS in Compile) <<= (fullOptJS in Compile).dependsOn(generateIndexTask("opt"))
The generated index.html will be located at the sample place as the generate .js files: ./target/scala-2.11
You should probably adjust the file paths to your own use.
For my own projects, I use another structure with a sbt-web project at the top level to manage all assets and the scala-js code in a sub-project that exports it's code as a webjar. It's more flexible.