mirror of
https://github.com/phfroidmont/scalive.git
synced 2025-12-24 21:26:58 +01:00
Setup example module with JS bundle configured
This commit is contained in:
parent
486e89c1f1
commit
aae3db841b
7 changed files with 39 additions and 7 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -4,3 +4,5 @@
|
||||||
.scala-build
|
.scala-build
|
||||||
secrets.env
|
secrets.env
|
||||||
out
|
out
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
|
|
||||||
29
build.mill
29
build.mill
|
|
@ -4,6 +4,10 @@ package build
|
||||||
|
|
||||||
import mill.*, scalalib.*, javascriptlib.*
|
import mill.*, scalalib.*, javascriptlib.*
|
||||||
import mill.api.Task.Simple
|
import mill.api.Task.Simple
|
||||||
|
import java.net.URI
|
||||||
|
import java.nio.file.*
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
|
import java.util
|
||||||
|
|
||||||
trait ScalaCommon extends ScalaModule:
|
trait ScalaCommon extends ScalaModule:
|
||||||
def scalaVersion = "3.7.2"
|
def scalaVersion = "3.7.2"
|
||||||
|
|
@ -15,10 +19,6 @@ trait ScalaCommon extends ScalaModule:
|
||||||
"-Wvalue-discard"
|
"-Wvalue-discard"
|
||||||
)
|
)
|
||||||
|
|
||||||
object js extends TypeScriptModule:
|
|
||||||
def npmDeps = Seq("morphdom@2.7.7")
|
|
||||||
def mainFileName = "index.ts"
|
|
||||||
|
|
||||||
object core extends ScalaCommon:
|
object core extends ScalaCommon:
|
||||||
// Replace with ujson, core shouldn't depend on ZIO
|
// Replace with ujson, core shouldn't depend on ZIO
|
||||||
def mvnDeps = Seq(mvn"dev.zio::zio-json:0.7.44")
|
def mvnDeps = Seq(mvn"dev.zio::zio-json:0.7.44")
|
||||||
|
|
@ -44,9 +44,30 @@ object core extends ScalaCommon:
|
||||||
object test extends ScalaTests with scalalib.TestModule.Utest:
|
object test extends ScalaTests with scalalib.TestModule.Utest:
|
||||||
def utestVersion = "0.9.0"
|
def utestVersion = "0.9.0"
|
||||||
|
|
||||||
|
object js extends TypeScriptModule:
|
||||||
|
def npmDeps = Seq("morphdom@2.7.7")
|
||||||
|
def mainFileName = "index.ts"
|
||||||
|
|
||||||
object zio extends ScalaCommon:
|
object zio extends ScalaCommon:
|
||||||
def mvnDeps = Seq(mvn"dev.zio::zio-http:3.4.0")
|
def mvnDeps = Seq(mvn"dev.zio::zio-http:3.4.0")
|
||||||
def moduleDeps = Seq(core)
|
def moduleDeps = Seq(core)
|
||||||
|
|
||||||
object example extends ScalaCommon:
|
object example extends ScalaCommon:
|
||||||
def moduleDeps = Seq(zio)
|
def moduleDeps = Seq(zio)
|
||||||
|
|
||||||
|
def scaliveBundle = Task {
|
||||||
|
os.copy(
|
||||||
|
from = example.js.bundle().path,
|
||||||
|
to = Task.dest / "public" / "app.js",
|
||||||
|
createFolders = true
|
||||||
|
)
|
||||||
|
PathRef(Task.dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
def resources = Task {
|
||||||
|
super.resources() ++ Seq(scaliveBundle())
|
||||||
|
}
|
||||||
|
|
||||||
|
object js extends TypeScriptModule:
|
||||||
|
def mainFileName = "app.ts"
|
||||||
|
def moduleDeps = Seq(core.js)
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,4 @@ el2.className = 'bar';
|
||||||
|
|
||||||
morphdom(el1, el2);
|
morphdom(el1, el2);
|
||||||
|
|
||||||
console.log("ok");
|
export const scalive = "scalive"
|
||||||
|
|
@ -3,6 +3,9 @@ import scalive.defs.complex.ComplexHtmlKeys
|
||||||
import scalive.defs.tags.HtmlTags
|
import scalive.defs.tags.HtmlTags
|
||||||
|
|
||||||
package object scalive extends HtmlTags with HtmlAttrs with ComplexHtmlKeys:
|
package object scalive extends HtmlTags with HtmlAttrs with ComplexHtmlKeys:
|
||||||
|
|
||||||
|
lazy val defer = htmlAttr("defer", codecs.BooleanAsOnOffStringCodec)
|
||||||
|
|
||||||
implicit def stringToMod(v: String): Mod = Mod.Content.Text(v)
|
implicit def stringToMod(v: String): Mod = Mod.Content.Text(v)
|
||||||
implicit def htmlElementToMod(el: HtmlElement): Mod = Mod.Content.Tag(el)
|
implicit def htmlElementToMod(el: HtmlElement): Mod = Mod.Content.Tag(el)
|
||||||
implicit def dynStringToMod(d: Dyn[String]): Mod = Mod.Content.DynText(d)
|
implicit def dynStringToMod(d: Dyn[String]): Mod = Mod.Content.DynText(d)
|
||||||
|
|
|
||||||
3
example/js/src/app.js
Normal file
3
example/js/src/app.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { scalive } from "core/js/index"
|
||||||
|
|
||||||
|
console.log(scalive)
|
||||||
|
|
@ -17,4 +17,6 @@ object Example extends ZIOAppDefault:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
override val run = Server.serve(liveRouter.routes).provide(Server.default)
|
val routes = liveRouter.routes @@ Middleware.serveResources(Path.empty / "static", "public")
|
||||||
|
|
||||||
|
override val run = Server.serve(routes).provide(Server.default)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ object RootLayout:
|
||||||
htmlRootTag(
|
htmlRootTag(
|
||||||
lang := "en",
|
lang := "en",
|
||||||
headTag(
|
headTag(
|
||||||
metaTag(charset := "utf-8")
|
metaTag(charset := "utf-8"),
|
||||||
|
scriptTag(defer := true, typ := "text/javascript", src := "/static/app.js")
|
||||||
),
|
),
|
||||||
bodyTag(
|
bodyTag(
|
||||||
content
|
content
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue