aboutsummaryrefslogtreecommitdiff
path: root/bin/uglifyjs2
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-08 12:55:18 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-08 12:55:18 +0300
commitdd8286bce152125d18a0af13a6088049303f2993 (patch)
treeaf290571ae07cd6bd42924e609d55f2a847c5ffd /bin/uglifyjs2
parent093a9031dc15b2e2bd85850f3f3eb7fe90f01bd7 (diff)
downloadtracifyjs-dd8286bce152125d18a0af13a6088049303f2993.tar.gz
tracifyjs-dd8286bce152125d18a0af13a6088049303f2993.zip
added --self to easily get a browser-runnable version of UglifyJS
Diffstat (limited to 'bin/uglifyjs2')
-rwxr-xr-xbin/uglifyjs220
1 files changed, 20 insertions, 0 deletions
diff --git a/bin/uglifyjs2 b/bin/uglifyjs2
index 17f82b58..ef87b657 100755
--- a/bin/uglifyjs2
+++ b/bin/uglifyjs2
@@ -43,6 +43,10 @@ because of dead code removal or cascading statements into sequences.")
.describe("stats", "Display operations run time on STDERR.")
.describe("acorn", "Use Acorn for parsing.")
.describe("spidermonkey", "Assume input fles are SpiderMonkey AST format (as JSON).")
+ .describe("self", "Build itself (UglifyJS2) as a library (implies --wrap=UglifyJS --export-all)")
+ .describe("wrap", "Embed everything in a big function, making the “exports” and “global” variables available. \
+You need to pass an argument to this option to specify the name that your module will take when included in, say, a browser.")
+ .describe("export-all", "Only used when --wrap, this tells UglifyJS to add code to automatically export all globals.")
.describe("v", "Verbose")
.alias("p", "prefix")
@@ -61,6 +65,9 @@ because of dead code removal or cascading statements into sequences.")
.string("c")
.string("d")
.string("comments")
+ .string("wrap")
+ .boolean("export-all")
+ .boolean("self")
.boolean("v")
.boolean("stats")
.boolean("acorn")
@@ -121,6 +128,15 @@ if (ARGS.comments) {
var files = ARGS._.slice();
+if (ARGS.self) {
+ if (files.length > 0) {
+ sys.error("WARN: Ignoring input files since --self was passed");
+ }
+ files = UglifyJS.FILES;
+ if (!ARGS.wrap) ARGS.wrap = "UglifyJS";
+ ARGS.export_all = true;
+}
+
var ORIG_MAP = ARGS.in_source_map;
if (ORIG_MAP) {
@@ -204,6 +220,10 @@ if (ARGS.acorn || ARGS.spidermonkey) time_it("convert_ast", function(){
TOPLEVEL = UglifyJS.AST_Node.from_mozilla_ast(TOPLEVEL);
});
+if (ARGS.wrap) {
+ TOPLEVEL = TOPLEVEL.wrap_commonjs(ARGS.wrap, ARGS.export_all);
+}
+
var SCOPE_IS_NEEDED = COMPRESS || MANGLE;
if (SCOPE_IS_NEEDED) {