如何从 Scala.js 导入 UglifyJS? [英] How to import UglifyJS from Scala.js?

查看:59
本文介绍了如何从 Scala.js 导入 UglifyJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以很好地使用 Scala.js 中的 jQuery:

I can use jQuery from Scala.js quite well:

jsDependencies += "org.webjars" % "jquery" % "2.2.1" / "jquery.js" minified "jquery.min.js"

现在我想使用 UglifyJS 并且它的 webjar 结构似乎有点不同.似乎没有缩小的 js 文件,甚至可能包含完整库的主文件看起来也不同,它没有 .js 扩展名,它以以下几行开头:

Now I would like to use UglifyJS and its webjar structure seems a bit different. There seems to be no minified js file, and even the main file which probably contains the complete library looks different, it has no .js extension and it starts with following lines:

#! /usr/bin/env node
// -*- js -*-

"use strict";

var UglifyJS = require("../tools/node");

这个 webjar 是否可以从 Scala.js 中使用,如果可以,如何使用?我尝试了以下操作,但没有奏效:

Can this webjar be used from Scala.js at all, and if it can, how? I have tried following, but it did not work:

jsDependencies += "org.webjars" % "uglifyjs" % "2.7.4" / "bin/uglifyjs"

这行 SBT 错误是:

With this line SBT error was:

[error] (test:resolvedJSDependencies) org.scalajs.core.tools.jsdep.JSLibResolveException:无法解析对 JS 库的某些引用:

[error] (test:resolvedJSDependencies) org.scalajs.core.tools.jsdep.JSLibResolveException: Some references to JS libraries could not be resolved:

[错误] - 缺少 JS 库:bin/uglifyjs

[error] - Missing JS library: bin/uglifyjs

[错误] 源自:scalafromjs:test, scalafromjs:compile

[error] originating from: scalafromjs:test, scalafromjs:compile

推荐答案

Uglify 发布为 uglify-js,而不是 uglifyjs.另外,没有为 2.7.4 版本创建一个 webjar,但是有一个用于 2.7.5.

Uglify is published as uglify-js, not uglifyjs. Also, a webjar was not created for version 2.7.4, however there is one for 2.7.5.

您只需点击几下 http://www 即可轻松请求自动创建 2.7.4 的 webjar.webjars.org/npm 如果您需要特定版本.

You can easily request automatic creation of a webjar for 2.7.4 in a few clicks on http://www.webjars.org/npm if you need it that specific version.

如果你去 webjars 网站搜索uglify-js",你会看到你需要使用的依赖配置:"org.webjars.npm" % "uglify-js" % "2.7.5"(加上你想要的文件).

If you go to the webjars website and search for "uglify-js", you'll see the dependency config you need to use: "org.webjars.npm" % "uglify-js" % "2.7.5" (plus the file you want).

请注意,从 0.6.14 开始,Scala.js 支持使用 scalajs-bundler.

这个新系统远远优于 webjar——你拥有所有可用的 npm 模块和版本,不需要自己触发创建(等到你进入 webjar 依赖项!),不需要等待索引更新,等

That new system is by far superior to webjars – you have ALL npm modules and versions available, no need to trigger creation yourself (wait till you get into webjar dependencies!), no need to wait for the index to be updated, etc.

这篇关于如何从 Scala.js 导入 UglifyJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆