3

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/

Community
  • 1
  • 1
ses
  • 13,174
  • 31
  • 123
  • 226

4 Answers4

5

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

  • i guess all that works if I use `crossProject`, in my case I use only one project, js one : `lazy val myChromePluginProject = Project(id = "my-project", base = file(".")).enablePlugins(ScalaJSPlugin). settings( artifactPath in(Compile, fastOptJS) := baseDirectory.value / "plugin" / "src" / "content" / "fastOpt.js",` ... it does not copy updated my question. – ses May 11 '16 at 02:08
  • This doesn't seem to work in Scala.js 1.3 (no cross-project), at least not for `fastLinkJS` – 0__ Jan 03 '21 at 15:45
2

Simply with this sbt setting:

crossTarget in fastOptJS := baseDirectory.value / "js"
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • seems does now work for me, i tried to put it in .settings(..) or outside of the project. I also tried with this: http://stackoverflow.com/questions/27505957/using-scala-js-to-compile-only-and-not-override-run-in-sbt eventhough there again two projects. – ses May 10 '16 at 01:20
  • 1
    `crossTarget in (Compile, fastOptJS)` then? – sjrd May 10 '16 at 08:02
2

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.

ses
  • 13,174
  • 31
  • 123
  • 226
1

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",
)
PokerFace
  • 811
  • 2
  • 9
  • 15