我正在尝试下面的hello world示例,其中的scalajs导出找到了here
@JSExportTopLevel("HelloWorld")
object HelloWorld {
@JSExport
def sayHello(): Unit = {
println("Hello world!")
}
}我的html看起来像这样:
<!DOCTYPE html>
<html>
<head>
<title>Example Scala.js application</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body style="margin: 0px">
<script type="text/javascript" src="./../../../target/scala-2.13/scala-js-tutorial-fastopt.js"></script>
<script>
HelloWorld.sayHello();
</script>
</body>
</html>它工作得很好。
现在,如果我尝试使用“./../target/scala-2.13/scalajs-bundler/main/scala-js-tutorial-fastopt-bundle.js”,(它在幕后使用了webpack ),运行fastOptJS::webpack并将路径更改为ScalaJSBundlerPlugin,我会得到"HelloWorld is not defined“。
捆绑后如何访问HelloWorld?
发布于 2020-10-12 19:52:58
默认情况下,scalajs-bundler使用"Application“绑定模式,该模式可以丢弃顶级导出。作为the cookbook explains,当使用@JSExportTopLevel时,您需要使用"LibraryAndApplication“绑定模式,使用
webpackBundlingMode := BundlingMode.LibraryAndApplication()https://stackoverflow.com/questions/64317090
复制相似问题