Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Generates a JS file for UglifyJS that can be used in web browsers

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 UglifyJS @ 8459929
Octocat-spinner-32 demo
Octocat-spinner-32 dist
Octocat-spinner-32 tools
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .gitmodules
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 generate.sh
README.md

uglifyweb

A tool that converts UglifyJS to work in a web browser.

It uses the RequirejS optimizer to convert the UglifyJS modules to AMD format, then uses a build with the tiny almond AMD shim to generate an uglifyweb.js file that does not have any dependencies and does not use RequireJS.

The uglifyweb.js file exports one global function, uglify, which is used the same as what is on the UglifyJS README. You can use uglify.parser() and uglify.uglify() where that page uses require('uglify-js').parser() and require('uglify-js').uglify().

The file also optionally registers as an AMD module called 'uglifyweb' if there is a global AMD define() function present. But an AMD loader is not required to use this file.

How to generate the JS file

> git clone --recursive https://github.com/jrburke/uglifyweb.git

If --recursive does not work with your version of git, do this after cloning:

> git submodule init
> git submodule update

That will pull the UglifyJS repo into the UglifyJS directory under this project.

> cd UglifyJS
> git checkout v1.1.1 (or whatever tag/branch you want)
> cd ..
> ./generate.sh

This will generate an uglifyweb.js file in this directory.

You will likely see errors when ./generate runs. This is OK. This is AMD converter complaining it cannot convert some files because, funny enough, the version of UglifyJS that the AMD converter uses cannot parse the file. However, the script files for UglifyJS are converted just fine.

Generated releases

There will be generated release occasionally added to the dist directory, but it will be infrequent and asks for updates will likely be ignored. It is best to generate your own copy using the steps above.

The versions in the dist directory correspond to the UglifyJS versions, not the version of this wrapper.

The latest available one is the one corresponding with UglifyJS 1.1.1.

How to use it in a web page

Just call uglify(). There is an example HTML page in demo/demo.html, but the basic idea:

    <script src="uglifyweb.js"></script>
    <script>var minified = uglify('some javascript string');</script>

Browser support

The generated file includes some array extras shims for reduce an forEach so that it will run in older IE browsers. Tested in IE 7, but should work in IE 6 too. All other browsers should work fine.

License

The parts that are unique to this repo (not much, just some wrapper code) are released under the new BSD and MIT licenses.

This project includes UglifyJS and some parts of es5-shim, both which have their own licenses:

Something went wrong with that request. Please try again.