How to copy Scala.js source maps using resourceGenerators?

I use resourceGenerators sbt key to copy fastOptJs generated .js files when using products , for example:

 (resourceGenerators in Compile) <+= (fastOptJS in Compile in frontend, packageScalaJSLauncher in Compile in frontend, packageJSDependencies in Compile in frontend) .map((f1, f2, f3) => { Seq(f1.data, f2.data, f3) }) 

Running the following in sbt, I see the path to the generated file:

 > show frontend/fastOptJS [info] Attributed(/some/path/frontend/target/scala-2.11/frontend-fastopt.js) [success] Total time: 0 s, completed Mar 12, 2016 1:59:22 PM 

Similarly, I can easily see where the Scala.js-generated launcher ends:

 > show frontend/packageScalaJSLauncher [info] Attributed(/some/path/frontend/target/scala-2.11/frontend-launcher.js) [success] Total time: 0 s, completed Mar 12, 2016 2:00:10 PM 

However, I can not find the task / key indicating the location of the .js.map file. I tried looking in the sources of the plugins, but could not find it. Is there a way to do this without resorting to creating a manual mapping in build.sbt ?

+5
source share
1 answer

The source maps created by Scala.js always have the name of the corresponding .js file + ".map" . So you can find one that is associated with f1 with f1.getParentFile / (f1.getName + ".map") .

Btw, the new assembly should not be used <+= . Instead, use the more understandable += :

 resourceGenerators in Compile += Def.task { val f1 = (fastOptJS in Compile in frontend).value.data val f1SourceMap = f1.getParentFile / (f1.getName + ".map") val f2 = (packageScalaJSLauncher in Compile in frontend).value.data val f3 = (packageJSDependencies in Compile in frontend).value Seq(f1, f1SourceMap, f2, f3) } 

and to avoid in Compile everywhere you can use inConfig(Compile) :

 inConfig(Compile)(Seq( resourceGenerators += Def.task { val f1 = (fastOptJS in frontend).value.data val f1SourceMap = f1.getParentFile / (f1.getName + ".map") val f2 = (packageScalaJSLauncher in frontend).value.data val f3 = (packageJSDependencies in frontend).value Seq(f1, f1SourceMap, f2, f3) } )) 
+5
source

Source: https://habr.com/ru/post/1244939/


All Articles