【问题标题】:In a ScalaJs sbt build, is there any advantage to use webjars instead of npm or bower with 'Provided'?在 ScalaJs sbt 构建中,使用 webjars 代替 npm 或 bower 是否有任何优势?
【发布时间】:2016-08-17 22:13:20
【问题描述】:

当我几个月前第一次发现 webJars 时,我非常怀疑这是否是一种处理客户端依赖项的可行方法,因为其中一些构建/构建系统非常复杂,并且考虑到 @ 987654322@ 文件已发布。第二个担忧当然没有充分的根据,但我觉得第一个问题是正确的,因为我花了将近 36 个小时现在徒劳地试图让大约 10 个scss/css/less-type webJars 和 8 个 JS webJars 生活在一个 jsDependencies 屋顶下。

当你达到 JS 依赖项 3、4 或 5 时,我发现你开始进入一个荒谬的 timekill 循环:

1。 “哦,不!fastOptJS 失败了,因为有一些随机文件也与 webjar 中的依赖项命名相同!”

[trace] Stack trace suppressed: run last client/compile:resolvedJSDependencies for the full output.
[error] (client/compile:resolvedJSDependencies) org.scalajs.core.tools.jsdep.JSLibResolveException: Some references to JS libraries could not be resolved:
[error] - Ambiguous reference to a JS library: bootstrap.min.js
[error]   Possible paths found on the classpath:
[error]   - META-INF/resources/webjars/bootstrap/3.3.6/js/bootstrap.min.js
[error]   - META-INF/resources/webjars/bootstrap3-dialog/1.34.4/examples/assets/bootstrap/js/bootstrap.min.js
[error]   originating from: client:compile, client:compile, client:compile, client:compile
[error] - Ambiguous reference to a JS library: bootstrap.js
[error]   Possible paths found on the classpath:
[error]   - META-INF/resources/webjars/bootstrap3-dialog/1.34.4/examples/assets/bootstrap/js/bootstrap.js
[error]   - META-INF/resources/webjars/bootstrap/3.3.6/js/bootstrap.js
[error]   originating from: client:compile, client:compile, client:compile, client:compile

2。我知道要做什么!我给定义的js加个版本!

lazy val           webjarbs   =   "org.webjars"               %    "bootstrap"                       % version.bootstrap  / s"${version.bootstrap}/bootstrap.js"                      minified s"${version.bootstrap}/bootstrap.min.js"         dependsOn    "jquery.js" commonJSName  "bootstrap"

3。 “哦不!fastOptJS 失败了!”

[trace] Stack trace suppressed: run last client/compile:resolvedJSDependencies for the full output.
[error] (client/compile:resolvedJSDependencies) org.scalajs.core.tools.jsdep.JSLibResolveException: Some references to JS libraries could not be resolved:
[error] - Missing JS library: 3.3.6/bootstrap.js
[error]   originating from: client:compile, client:compile, client:compile, client:compile
[error] - Missing JS library: 3.3.6/bootstrap.min.js
[error]   originating from: client:compile, client:compile, client:compile, client:compile

男孩们。

这样一遍又一遍,然后我必须开始做

lazy val         bs_sidebar   = ( "org.webjars"               %    "bootstrap-sidebar"              % version.bs_sidebar intransitive())  / "js/sidebar.js" dependsOn(s"bootstrap.js",  s"bootstrap.min.js")

现在我什至没有真正使用 webjar,但它有一个名为 X 的 js依赖项,我无法更改它...

问题

嗯?如果我只是做了我过去常做的事情,只是将没有应用程序的依赖项构建到某个巨大的文件或一组文件中,然后将其输入到构建中怎么办?我有一个来自网上的概念证明,我得到了它的工作(我认为它是 https://github.com/wav/material-ui-scalajs-react/blob/master/src/main/scala/wav/web/muiwrapper/package.scala )几乎工作,并给了我这个想法。

我知道npm 比sbt, 工作得更好,而且我仍然可以将它放入我的包中...有什么缺点,我是否遗漏了一些关于 sbt 的内容?

【问题讨论】:

    标签: node.js sbt scala.js sbt-web


    【解决方案1】:

    我同意你的看法。一旦应用程序开始对 JavaScript 库产生重要的依赖,jsDependencies 就无法扩展。这主要是因为 WebJars 缺少关键特性(就像传递依赖一样),还因为 jsDependencies 不是一种旨在扩展的机制。

    随着时间的推移,用户对jsDependencies 的功能提出了越来越多的要求,因为他们希望将其用作他们真正的应用程序规模(无论这意味着什么)依赖机制。因此,我们在jsDependencies 之上修补了越来越多的功能/黑客。结果不是世界上最漂亮的东西,它肯定有缺点。

    我实际上鼓励使用npm 来解决您的依赖关系,特别是如果您熟悉它并且知道如何将其集成到您的工作流程中。

    【讨论】:

    • recently announced scalajs-bundler 如何适应这个?展望未来,或者对于非平凡的应用程序,您应该从 jsDependencies 迁移到 npmDependencies?
    • 预计大多数复杂的构建最终会转向比jsDependencies更有原则的东西。 npmDependencies 绝对是一种选择。
    【解决方案2】:

    在我看来,使用 web jar 的主要优点是不必使用 npm。另外,他们通过通常的 maven 解析/下载过程,所以虽然它并不完美,但它只是一个破损管道而不是两个。

    无论如何,它们可能会很痛苦。我的 scala.js 应用程序中有大约 30 个依赖项,它们主要由 web jar 管理。我发现,总的来说,使用 npm webjars 与 bower webjars 相比,我得到了更好的结果,而且尝试依赖 web jar 传递依赖项是愚蠢的。

    我的jsDependencies 看起来像这样:

    ("org.webjars" % "morrisjs" % "0.5.1" intransitive ())
            / "morris.js"
            minified "morris.min.js"
            dependsOn "2.1.2/raphael.js",
    ("org.webjars" % "raphaeljs" % "2.1.2-1" intransitive ())
            / "2.1.2/raphael.js"
            minified "2.1.2/raphael-min.js"
    

    首先要注意的是版本号被破坏到基本上所有依赖的东西上。如果它被大量使用,我将版本提取到一个变量中。第二件事是intransitive() 注释。虽然有时我可以不用它而侥幸逃脱,但我发现直言不讳可以让事情顺利进行,让我的头发保持在适当的位置。

    我倾向于坚持使用前端友好的软件包,例如 react 和 angular。一些新的 React 库有几十个传递依赖,尝试使用它们会很痛苦。我避免那些=p

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-26
      • 2017-03-04
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      相关资源
      最近更新 更多