'ScalaJS to simply redirect complication output to specified directory
By Scala.js' sbt fastOptJS, I would simply want to redirect myproject/target/scala-2.11/web-fastopt.js to myproject/js is that possible?
Same for web-jsdeps.js - to redirect it to /myproject/libs
I've read this Scala.js compilation destination
that seems too complicated. I have only one project, not two or three, there is no play framework, just plain file-to-folder copy.
UPDATE:
My settings, project/BuildProject.scala:
lazy val chromePluginProject = Project(id = "chromePlugin", base = file(".")).enablePlugins(ScalaJSPlugin).
settings(
version := "0.1",
scalaVersion := Versions.scala,
artifactPath in(Compile, fastOptJS) := baseDirectory.value / "plugin" / "src" / "content" / "fastOpt.js",
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }, // TODO:
//mainClass := Some("branch.ScalaJsSample"),
libraryDependencies ++= scalaJsDependencies,
libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.9.0",
libraryDependencies += "com.lihaoyi" %%% "upickle" % Versions.upickle,
libraryDependencies += "com.lihaoyi" %%% "scalatags" % Versions.scalaTags,
// we will not use use DOM directly so commenting it
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % Versions.dom,
jsDependencies += "org.webjars" % "jquery" % Versions.jquery / "jquery.js",
jsDependencies += "org.webjars.bower" % "webcomponents.js" % Versions.webcomponents / "webcomponents-lite.js",
// After reloading and rerunning fastOptJS,
// this will create scala-js-jsdeps.js
skip in packageJSDependencies := false,
// allows DOM be available from from console' run (so no "ReferenceError: "window" is not defined." error would appear)
jsDependencies += RuntimeDOM, // it will use PhantomJS, basically
scalaJSUseRhino in Global := false //will use node.js to run the thing
)
My file structure is:
<root>/plugin/src/content where I want to copy the fastOpt.js
As i said it creates in *-site-jsdeps.js in /target/scala-2.11/
Solution 1:[1]
Yes, You can do it like this:
artifactPath in(Compile, packageScalaJSLauncher) := baseDirectory.value / ".." / "jvm" / "webapp" / "js" / "launcher.js",
artifactPath in(Compile, fastOptJS) := baseDirectory.value / ".." / "jvm" / "webapp" / "js" / "fastOpt.js",
artifactPath in(Compile, fullOptJS) := baseDirectory.value / ".." / "jvm" / "webapp" / "js" / "fullOpt.js",
artifactPath in(Compile, packageJSDependencies) := baseDirectory.value / ".." / "jvm" / "webapp" / "js" / "dependency.js"
for more, you can refer to https://github.com/yuanqingfei/gdbscan-akka-d3js/blob/master/build.sbt
Solution 2:[2]
Simply with this sbt setting:
crossTarget in fastOptJS := baseDirectory.value / "js"
Solution 3:[3]
in your BuildProject.scala (object BuildProject extends Build {) or build.sbt add this line:
lazy val copyJsTask = TaskKey[Unit]("copyJsTask", "Copy javascript files to target directory")
lazy val myPluginProject = Project(id = "my-plugin", base = file(".")).
settings(
copyJsTask := {
val outDir = baseDirectory.value / "plugin/src/content"
val inDir = baseDirectory.value / "target/scala-2.11"
val files = Seq("my-plugin-fastopt.js", "my-plugin-fastopt.js.map") map { p => (inDir / p, outDir / p) }
IO.copy(files, overwrite = true)
}, ..
add new file in the very root of your project .sbtrc
with the content:
alias jsCompile=;fastOptJS;copyJsTask
--
That what satisfies me with its "complexity", npm/grunt/linux batch alike.
Solution 4:[4]
With sbt v1.6.1 you can add these settings to change the output directory of Scala.js.
settings(
Compile / fastOptJS / artifactPath := baseDirectory.value / "../where-you-like/main.js",
Compile / fullOptJS / artifactPath := baseDirectory.value / "../where-you-like/main.js",
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yuanqingfei |
| Solution 2 | sjrd |
| Solution 3 | |
| Solution 4 | PokerFace |
