73745

How to import UglifyJS from Scala.js?

Question:

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 <a href="https://github.com/mishoo/UglifyJS" rel="nofollow">UglifyJS</a> 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:

<blockquote>

[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

</blockquote>

Answer1:

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 <a href="http://www.webjars.org/npm" rel="nofollow">http://www.webjars.org/npm</a> 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).

<hr />

<strong>Note that as of 0.6.14 Scala.js supports npm modules using <a href="https://scalacenter.github.io/scalajs-bundler/getting-started.html" rel="nofollow">scalajs-bundler</a></strong>.

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.

Recommend

  • How can I selectively modify the src attributes of script tags in an HTML document using Perl?
  • Rails 4.1 environment variables not reloading
  • How to create a custom Powershell operator?
  • File loader changed image file name but not the file name in HTML file
  • Write output of for loop to multiple files
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Simple linked list-C
  • nodemcu custom firmware build problems
  • Android Studio Can't Find tools.jar
  • Convert SQLite database to XML
  • Redirect STDERR in OPEN pipe comand. Perl Linux
  • cygwin cannot exec 'git-add--interactive' permission denied
  • CakePHP ACL tutorial initDB function warnings
  • rspec simple example getting error on request variable in integration test
  • Eclipse CDT error: Unable to compile
  • error importing numpy
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • How to attach a node.js readable stream to a Sendgrid email?
  • MongoError: Incorrect arguments
  • Read a local file using javascript
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • R - Combining Columns to String Based on Logical Match
  • Why is an OPTIONS request sent to the server?
  • Read text file and split every line in MSBuild
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Spray.io: When (not) to use non-blocking route handling?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Return words with double consecutive letters
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • how to add data labels for bar graph in matlab
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Comma separated Values
  • How to delete a row from a dynamic generate table using jquery?
  • using HTMLImports.whenReady not working in chrome
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection
  • How can i traverse a binary tree from right to left in java?
  • How to load view controller without button in storyboard?