11package com .ossuminc .sbt .helpers
22
33import sbt .*
4- import sbt .Keys .libraryDependencies
4+ import sbt .Keys .*
55import org .scalajs .sbtplugin .ScalaJSPlugin
66import org .scalajs .sbtplugin .ScalaJSPlugin .autoImport .*
77import org .portablescala .sbtplatformdeps .PlatformDepsPlugin .autoImport .*
88import org .scalajs .linker .interface .ModuleSplitStyle
9+ import com .github .sbt .git .GitPlugin .autoImport .git
910
10- object Javascript extends AutoPluginHelper {
11+ object ScalaJS extends AutoPluginHelper {
1112
1213 override def configure (project : Project ): Project = apply()(project)
1314
@@ -23,6 +24,23 @@ object Javascript extends AutoPluginHelper {
2324 .enablePlugins(ScalaJSPlugin )
2425 // .settings(ScalaJSPlugin.testConfigSettings) <-- generates undefined settings
2526 .settings(
27+ // For source maps in Scala
28+ scalacOptions ++= {
29+ // Map the sourcemaps to github paths instead of local directories
30+ val flag =
31+ if (scalaVersion.value.startsWith(" 3" )) " -scalajs-mapSourceURI"
32+ else " -P:scalajs:mapSourceURI"
33+ val localSourcesPath = baseDirectory.value.toURI
34+ val headCommit = git.gitHeadCommit.value.get
35+ scmInfo.value.map { info =>
36+ val remoteSourcesPath =
37+ s " ${
38+ info.browseUrl.toString
39+ .replace(" github.com" , " raw.githubusercontent.com" )
40+ }/ $headCommit"
41+ s " ${flag}: $localSourcesPath-> $remoteSourcesPath"
42+ }
43+ },
2644 // for an application with a main method
2745 scalaJSUseMainModuleInitializer := hasMain,
2846 scalaJSLinkerConfig ~= {
0 commit comments