0

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

Suma
  • 33,181
  • 16
  • 123
  • 191

1 Answers1

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.

Nikita
  • 2,924
  • 1
  • 19
  • 25
  • I experience the same problem with [2.7.5 uglify-js](https://mvnrepository.com/artifact/org.webjars.npm/uglify-js) as I did with [2.7.4 uglifyjs](https://mvnrepository.com/artifact/org.webjars/uglifyjs). Its jar archive does not contain `uglifyjs.js`, only `bin/uglifyjs`. – Suma Feb 03 '17 at 09:35
  • The `scalajs-bundler` is promising, but there are probably some additional steps to get it working. It adds dependencies not into `scalafromjs-test-jsdeps.js`, but into `scalajs-bundler/scalafromjs-test-fastopt.js`, therefore running app or tests normally does not load the dependencies. – Suma Feb 03 '17 at 09:54
  • I have posted [a new question](https://stackoverflow.com/questions/42021880/how-to-use-scalajs-bundler-with-client-only-app) about the client-only use. – Suma Feb 03 '17 at 10:18
  • Sorry, I don't know too much about how webjars are supposed to work. After many frustrations, I've jumped ship to scala-js-bundler and haven't used webjars since. Someone gave a correct answer to your new question already. Good luck! – Nikita Feb 04 '17 at 04:22