sbt new mobilemindtech/pagereload4s.g8 pagereloadStartStart the reload pluginpagereloadStopStop the reload pluginpagereloadServeStart http serverpagereloadWatchStart file watcher
pathWatchToReload: File | Null = nullPath to watch to reload on changewatchDefaultTargetToCopy: Boolean = trueWatch target folder to copy artifacts on changescopyJsToPath: File | Null = nullDestination path to copy artifactscopyJsToFile: File | Null = nullCopy js to a specific file, example /path/js/main.jspublicFolder: File | Null = nullPublic folder to servedebug: Boolean = falseDebug modenotificationDelay: Long = 1000Delay to send reload notification to websocket clientserverPort: Int = 10101Server portextensions: Seq[String] = Seq("js", "map", "css", "jpg", "jpeg", "png", "ico", "html")File extensions to watchreloadURL: String | Null = nullURL to reload on change, default is http://localhost:10101renameRules: Map[String, String] = Map.emptyRename rules. Eg.:Map("main" -> "myapp")
This plugin can be used to copy the generated JS to an external project. For example, to go lang or node application. In this case we need to specify the location where the js will be copied, the folder we want to watch to reload on change and the URL to reload.
Config example:
Given the project structure:
my-go-app/
public/
js/
my-scalajs-app/
src/Configure the plugin in the build.sbt of the scalajs project:
.enablePlugins(ScalaJSPlugin, PageReload4sPlugin)
.settings(
pagereload := ReloadConfig(
pathWatchToReload = baseDirectory.value / ".." / "my-go-app" / "public" / "js",
copyJsToPath = baseDirectory.value / ".." / "my-go-app" / "public" / "js",
reloadURL = "http://localhost:9000/myapp/mypage"
)
)Add the script in your HTML page:
<script type="text/javascript" src="http://localhost:10101/js/livereload.js"></script>`addSbtPlugin("br.com.mobilemind" % "pagereload4s" % "0.4.0")example/
src/
public/
index.html
assets/
js/ThisBuild / name := "example"
ThisBuild / scalaVersion := "3.8.4"
lazy val app = (project in file("."))
.enablePlugins(ScalaJSPlugin, PageReload4sPlugin)
.settings(
name := "example",
scalaJSUseMainModuleInitializer := true,
pagereload := ReloadConfig(
pathWatchToReload = baseDirectory.value / "public",
publicFolder = baseDirectory.value / "public",
copyJsToPath = baseDirectory.value / "public" / "assets" / "js",
debug = true
),
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-dom" % "2.8.1"
)
)
- Add on HTML page
<script type="text/javascript" src="http://localhost:10101/js/livereload.js"></script>- In the sbt console execute
sbt:appjs> livereloadStart
- Run ~fastLinkJS to compile scalajs files.
sbt:appjs> ~fastLinkJS
When you change a file, the browser will be reloaded.
- In the example project, run sbt:
sbt:appjs> pagereloadStart
- Open the test page on http://localhost:10101/sample/index.html.
sbt:appjs> ~fastLinkJS
- Change
Main.scalaand save to HTML reload.
local
sbt:appjs> sbt publishLocal
maven central
sbt sonatypeBundleRelease