适用于Three.js的新Scala.js外观->&引用;找不到模块";“三”&引用;

适用于Three.js的新Scala.js外观->&引用;找不到模块";“三”&引用;,three.js,scala.js,facade,transpiler,scalajs-bundler,Three.js,Scala.js,Facade,Transpiler,Scalajs Bundler,由于已经严重过时,我尝试了如下方法:并希望为新的three.js库创建一个外观 我决不是JS专家,也不是Scala.JS专家,所以我很可能在做一些非常愚蠢的事情 在另一个问题之后,我正在使用这个sbt-scalajs绑定器和sbt-web-scalajs绑定器 我的build.sbt如下所示: lazy val client = (project in file("modules/client")) .enablePlugins(ScalaJSBundlerPlugin, ScalaJSWe

由于已经严重过时,我尝试了如下方法:并希望为新的
three.js
库创建一个外观

我决不是
JS
专家,也不是
Scala.JS
专家,所以我很可能在做一些非常愚蠢的事情

在另一个问题之后,我正在使用这个
sbt-scalajs绑定器
sbt-web-scalajs绑定器

我的
build.sbt
如下所示:

lazy val client = (project in file("modules/client"))
  .enablePlugins(ScalaJSBundlerPlugin, ScalaJSWeb) // ScalaJSBundlerPlugin automatically enables ScalaJSPlugin
  .settings(generalSettings: _*)
  .settings(
    name := "client"
    //, scalaJSModuleKind := ModuleKind.CommonJSModule // ScalaJSBundlerPlugin implicitly sets moduleKind to CommonJSModule enables ScalaJSPlugin
   ,jsDependencies += ProvidedJS / "three.min.js"
  )

lazy val server = (project in file("modules/server"))
  .enablePlugins(PlayScala, WebScalaJSBundlerPlugin)
  .settings(generalSettings: _*)
  .settings(
    name := "server"
    ,scalaJSProjects := Seq(client)
    ,pipelineStages in Assets := Seq(scalaJSPipeline)
    //,pipelineStages := Seq(digest, gzip)
    ,compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
  )
three.min.js
位于我的
客户端
项目的resources文件夹中

正面的一部分是,例如

@js.native
@JSImport("THREE", "Scene")
class Scene extends Object3D {
我想这样使用:
val scene=new scene
。在
scala.js
端,这实际上编译得很好,但当我运行它时,我得到:

错误:找不到模块“三”

在浏览器中,我想知道为什么。毕竟在
three.min.js
中是这样调用的

现在我也尝试从服务器端提供并服务
three.min.js
文件,因为我认为它可能只是在运行时丢失了,但不,这似乎不是原因

现在我想知道我做错了什么

只是想澄清一下:如果我不导出Facade的任何用法,transpiled
js
的其余部分工作得很好

如Scala.js文档中的解释,
@JSImport
被编译器解释为JavaScript模块导入

当您使用
CommonJSModule
模块类型时(启用
ScalaJSBundlerPlugin
),此导入将转换为以下CommonJS导入:

var Scene = require("THREE").Scene;
这个注释只告诉您的Scala代码将如何与JS世界接口,但它没有告诉您如何解决提供
THREE
模块的依赖关系


使用scalajs bundler,您可以通过将以下设置添加到
客户机
项目来定义:

npmDependencies += "three" -> "0.84.0"
(请注意,您不能使用
jsDependencies
使用
@JSImport
解析这些模块)

另外,请注意使用three.js的正确CommonJS导入是
“three”
,而不是
“three”
,因此您的
@JSImport
注释应该如下所示:

@JSImport("three", "Scene")

或者,如果您不想从NPM注册表解析依赖项,可以将CommonJS模块作为资源文件提供。只需将它放在
src/main/resources/Scene.js下,并在
@JSImport
中引用它,如下所示:

@JSImport("./Scene", "Scene")

您可以看到一个工作示例。

也许这就是您想要的:谢谢,但我想自己提供js文件