我尝试制作一个简单的scalajs + scalajs-bootstrap应用程序,但是关于如何设置骨架的文档很少。scalajs-bootstrap 项目有一个示例,但是 build.sbt 文件非常大,它包含 scalajs-bootstrap 的源代码和示例本身。
我尝试仅使用 bootstrap4 示例创建一个新项目,但是当我在浏览器上打开 index.html 页面时,它会抱怨
Uncaught ReferenceError: exports is not defined at scalajsenv.js:29
这是我目前的设置:
项目/plugins.sbt
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20")
addSbtPlugin("com.github.karasiq" % "sbt-scalajs-bundler" % "1.2.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.0")
构建.sbt
enablePlugins(ScalaJSBundlerPlugin)
scalaVersion := "2.12.6"
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.7"
libraryDependencies += "com.github.karasiq" %%% "scalajs-bootstrap-v4" % "2.3.5"
npmDependencies in Compile += "jquery" -> "3.2.1"
npmDependencies in Compile += "bootstrap" -> "4.1.1"
mainClass in Compile := Some("com.karasiq.bootstrap4.test.frontend.BootstrapTestApp")
scalaJSUseMainModuleInitializer := true
scalaJSModuleKind := ModuleKind.CommonJSModule
version in webpack := "4.28.4"
emitSourceMaps := false
这是 scalajs-bootstrap4 libray 的源代码和示例: https ://github.com/Karasiq/scalajs-bootstrap
这是我完整的最小示例,失败并出现exports is not defined
错误:
https ://github.com/dportabella/scalajs-bootstrap4-examples
如何修改 plugins.sbt 和/或 build.sbt 以使这个项目工作?
解决方案
项目/plugins.sbt
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.0")
构建.sbt
enablePlugins(ScalaJSBundlerPlugin)
scalaVersion := "2.12.8"
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.7"
libraryDependencies += "com.github.karasiq" %%% "scalajs-bootstrap-v4" % "2.3.5"
npmDependencies in Compile += "jquery" -> "3.2.1"
npmDependencies in Compile += "bootstrap" -> "4.1.1"
mainClass in Compile := Some("com.karasiq.bootstrap4.test.frontend.BootstrapTestApp")
scalaJSUseMainModuleInitializer := true
scalaJSModuleKind := ModuleKind.CommonJSModule
version in webpack := "4.28.4"
emitSourceMaps := false
完整示例: https ://github.com/dportabella/scalajs-bootstrap4-examples