How to import UglifyJS from Scala.js?

陌路散爱 提交于 2019-12-12 01:39:20

问题


I can use jQuery from Scala.js quite well:

jsDependencies += "org.webjars" % "jquery" % "2.2.1" / "jquery.js" minified "jquery.min.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");

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"

With this line SBT error was:

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

[error] - Missing JS library: bin/uglifyjs

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


回答1:


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.

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.

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).


Note that as of 0.6.14 Scala.js supports npm modules using scalajs-bundler.

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.



来源:https://stackoverflow.com/questions/42012243/how-to-import-uglifyjs-from-scala-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!