aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-18 15:49:15 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-18 15:49:15 +0300
commit6f45928a73009b6b1aee8c1886f08ff5b83e6cb1 (patch)
treed5a70ad631497ef04907a6667833dc9b0be9f425
parentafb7faa6fadee46a6ab46232eddba2121c77549b (diff)
downloadtracifyjs-6f45928a73009b6b1aee8c1886f08ff5b83e6cb1.tar.gz
tracifyjs-6f45928a73009b6b1aee8c1886f08ff5b83e6cb1.zip
add fromString argument to `UglifyJS.minify` (allows to pass the source
code, instead of file names, as first argument). close #17
-rw-r--r--README.md7
-rw-r--r--tools/node.js7
2 files changed, 12 insertions, 2 deletions
diff --git a/README.md b/README.md
index 8cf0ba42..f519c119 100644
--- a/README.md
+++ b/README.md
@@ -322,6 +322,7 @@ There's a single toplevel function which combines all the steps. If you
don't need additional customization, you might want to go with `minify`.
Example:
+ // see "fromString" below if you need to pass code instead of file name
var result = UglifyJS.minify("/path/to/file.js");
console.log(result.code); // minified output
@@ -354,6 +355,12 @@ can use the `inSourceMap` argument:
The `inSourceMap` is only used if you also request `outSourceMap` (it makes
no sense otherwise).
+Other options:
+
+- `warnings` (default `false`) — pass `true` to display compressor warnings.
+- `fromString` (default `false`) — if you pass `true` then you can pass
+ JavaScript source code, rather than file names.
+
We could add more options to `UglifyJS.minify` — if you need additional
functionality please suggest!
diff --git a/tools/node.js b/tools/node.js
index 07c3bfae..6a21710a 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -66,6 +66,7 @@ exports.minify = function(files, options) {
options = UglifyJS.defaults(options, {
outSourceMap : null,
inSourceMap : null,
+ fromString : false,
warnings : false,
});
if (typeof files == "string")
@@ -74,9 +75,11 @@ exports.minify = function(files, options) {
// 1. parse
var toplevel = null;
files.forEach(function(file){
- var code = fs.readFileSync(file, "utf8");
+ var code = options.fromString
+ ? file
+ : fs.readFileSync(file, "utf8");
toplevel = UglifyJS.parse(code, {
- filename: file,
+ filename: options.fromString ? "?" : file,
toplevel: toplevel
});
});